|
72 | 72 | "increment()\n", |
73 | 73 | "print(i) # Even if it didn't error, it would print 1\n", |
74 | 74 | "```\n", |
| 75 | + "\n", |
| 76 | + "```{figure} ../images/alpaca/bad_coding_practices.png\n", |
| 77 | + "---\n", |
| 78 | + "max-height: 300px\n", |
| 79 | + "name: ALPACA doesn't know what i is\n", |
| 80 | + "class: no-invert\n", |
| 81 | + "---\n", |
| 82 | + "```\n", |
75 | 83 | ":::\n", |
76 | 84 | "\n", |
77 | 85 | ":::{admonition} DO\n", |
|
89 | 97 | "i = increment(i)\n", |
90 | 98 | "print(i) # 2\n", |
91 | 99 | "```\n", |
| 100 | + "\n", |
| 101 | + "```{figure} ../images/alpaca/good_coding_practices.png\n", |
| 102 | + "---\n", |
| 103 | + "max-height: 300px\n", |
| 104 | + "name: ALPACA does know what i is\n", |
| 105 | + "class: no-invert\n", |
| 106 | + "---\n", |
| 107 | + "```\n", |
92 | 108 | ":::\n", |
93 | 109 | "\n", |
94 | 110 | "## Dealing with data\n", |
|
103 | 119 | "\n", |
104 | 120 | "# Modules\n", |
105 | 121 | "\n", |
106 | | - "Some modules aren't available in ALPACA and some modules aren't available in the computer. These are the **modules that are available on ALPACA only:**\n", |
| 122 | + "Some modules aren't available in ALPACA and some modules aren't available in the computer. These are the **modules that are available on ALPACA only** you have to import them inside the functions.\n", |
107 | 123 | "\n", |
108 | 124 | "## `machine` - functions related to the hardware\n", |
109 | 125 | "\n", |
110 | 126 | "This module contains functions to control hardware on ALPACA like the digital pins or the analog to digital converter. You will explore this module while [working with signals](./signals.ipynb).\n", |
111 | 127 | "\n", |
| 128 | + "## `helper` - functions to talk with Helper Pico\n", |
| 129 | + "\n", |
| 130 | + "Helper Pico controls several functions on ALPACA board itself. You can send the following commands:\n", |
| 131 | + "\n", |
| 132 | + "\n", |
| 133 | + "| Function | Description |\n", |
| 134 | + "|----------|--------------|\n", |
| 135 | + "| `set_screen_text(text_up: string, text_down: string)` | Sets the text on `CSTM` display on the LCD panel |\n", |
| 136 | + "\n", |
| 137 | + "<span style=\"background:#ff1493;color:#fff;padding:2px 8px;border-radius:4px;font-weight:700;font-size:0.85em;box-shadow:0 0 6px rgba(255,20,147,0.6);\">🚩 TODO: Add FuncGen implementation add AWG as deep dive.</span>\n", |
| 138 | + "\n", |
| 139 | + "\n", |
| 140 | + "The `CSTM` screen is connected to Helper Pico, so you can send a command to change the text\n", |
| 141 | + "\n", |
| 142 | + "```python\n", |
| 143 | + "@pico.task\n", |
| 144 | + "def change_text_on_screen():\n", |
| 145 | + " import helper\n", |
| 146 | + "\n", |
| 147 | + " helper.set_screen_text(\"Hello :)\", \"Alpaca\")\n", |
| 148 | + "```\n", |
112 | 149 | "\n", |
113 | 150 | "## `utime` - time related functions\n", |
114 | 151 | "\n", |
115 | 152 | "When working with signals you need to deal with time-senstivity at microscale. `utime` provides functions for this exact purpose.\n", |
116 | 153 | "\n", |
| 154 | + "| Function | Description |\n", |
| 155 | + "|----------|--------------|\n", |
| 156 | + "| `sleep(sec: float)` | Sleep (waits) for a given number of **seconds** (can be a float) |\n", |
| 157 | + "| `sleep_ms(ms: int)` | Sleep (waits) for a given number of **milliseconds** |\n", |
| 158 | + "| `sleep_us(us: int)` | Sleep (waits) for a given number of **microseconds** |\n", |
| 159 | + "| `ticks` | Returns current uptime (now) in **seconds** |\n", |
| 160 | + "| `ticks_us` | Returns current uptime (now) in **ms** |\n", |
| 161 | + "| `ticks_ms` | Returns current uptime (now) in **us** |\n", |
| 162 | + "| `ticks_diff(a, b)` | Perform a-b on ticks |\n", |
| 163 | + "| `ticks_add(a, b)` | Perform a+b on ticks |\n", |
| 164 | + "\n", |
117 | 165 | "```python\n", |
118 | 166 | "@pico.task\n", |
119 | 167 | "def blink_led():\n", |
|
186 | 234 | "metadata": {}, |
187 | 235 | "source": [ |
188 | 236 | "\n", |
189 | | - "But the <font color=\"#00819b\">tick</font> itself is never useful cause sometimes <font color=\"#00819b\">**it rollsover to 0 (as it can't count forever)**</font> (see the figure above). Therefore, using `utime.ticks_add(a, b)` and `utime.ticks_diff(a, b)` (basically a + b and a - b) is <font color=\"#00819b\">**essential**</font> when calculating time.\n", |
| 237 | + "But the <font color=\"#00819b\">tick</font> itself is never useful cause sometimes <font color=\"#00819b\">**it rollsover to 0 (as it can't count forever)**</font> (see the figure above). So just doing `tick_a - tick_b` can give invalid results, using `utime.ticks_add(a, b)` and `utime.ticks_diff(a, b)` (basically a + b and a - b) is <font color=\"#00819b\">**essential**</font> when calculating time.\n", |
190 | 238 | "\n", |
191 | 239 | "```python\n", |
192 | 240 | "@pico.task\n", |
|
209 | 257 | " total += adc0.read_u16()\n", |
210 | 258 | "\n", |
211 | 259 | " return total * 3.3 / 2**16 / n\n", |
212 | | - "```" |
| 260 | + "```\n", |
| 261 | + "\n", |
| 262 | + "\n", |
| 263 | + "## `dac` - digital-to-analog converter\n", |
| 264 | + "\n", |
| 265 | + "See [Digital-to-Analog Converter](./signals.ipynb#generation-dac-digital-to-analog-converter)." |
213 | 266 | ] |
214 | 267 | } |
215 | 268 | ], |
|
0 commit comments