{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b8a81d77-1483-4bbf-abe4-ff7844df47d9",
   "metadata": {},
   "source": [
    "## Príklad č. 1: Riadenie výstpov pomocou B-funkcií"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "747f22d6-bd70-4acb-9f75-97f7c963a10d",
   "metadata": {},
   "outputs": [],
   "source": [
    "%serialconnect\n",
    "\n",
    "from machine import Pin\n",
    "import time\n",
    "\n",
    "# definovanie vstupov a vystupov\n",
    "pinA = Pin(25, Pin.IN)\n",
    "pinB = Pin(33, Pin.IN)\n",
    "pinC = Pin(32, Pin.IN)\n",
    "pinY = Pin(18, Pin.OUT)\n",
    "\n",
    "# hlavny program\n",
    "while True:\n",
    "    # nacitanie hodnot vstupov\n",
    "    A = pinA.value() \n",
    "    B = pinB.value()\n",
    "    C = pinC.value()\n",
    "    \n",
    "    # vypocet hodnoty vystupu pomocou funkcie\n",
    "    Y = A * (not B) + C + (not A) * B * C\n",
    "    # Y = A and (not B) or C or (not A) and B and C\n",
    "    # Y = A & (~B) | C | (~A) & B & C\n",
    "    \n",
    "    # zapisanie vyslednej hodnoty\n",
    "    pinY.value(Y)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3f72b33-74a5-4a63-b273-92a30a8d3154",
   "metadata": {},
   "source": [
    "## Príklad č. 2: Riadenie výstupov pomocou pravdivostnej tabuľky"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec73b597-8744-4a5a-a1e1-eddaf5e3416c",
   "metadata": {},
   "outputs": [],
   "source": [
    "%serialconnect\n",
    "\n",
    "from machine import Pin\n",
    "import time\n",
    "\n",
    "# definovanie vstupov a vystupov\n",
    "pinA = Pin(25, Pin.IN)\n",
    "pinB = Pin(33, Pin.IN)\n",
    "pinC = Pin(32, Pin.IN)\n",
    "pinY = Pin(18, Pin.OUT)\n",
    "\n",
    "# definovanie pravdivostnej tabulky\n",
    "tab = {\n",
    "  (0, 0, 0): 0,\n",
    "  (0, 0, 1): 1,\n",
    "  (0, 1, 0): 1,\n",
    "  (0, 1, 1): 0,\n",
    "  (1, 0, 0): 0,\n",
    "  (1, 0, 1): 0,\n",
    "  (1, 1, 0): 0,\n",
    "  (1, 1, 1): 1\n",
    "}\n",
    "\n",
    "# hlavny program\n",
    "while True:\n",
    "    # nacitanie hodnot vstupov\n",
    "    A = pinA.value() \n",
    "    B = pinB.value()\n",
    "    C = pinC.value()\n",
    "    \n",
    "    # vypocet hodnoty vystupu pomocou tabulky\n",
    "    Y = tab[A, B, C]\n",
    "    \n",
    "    # zapisanie vyslednej hodnoty\n",
    "    pinY.value(Y)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
