You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert

312
312
**Figure.** The back and front sides of an 8-LED WS2812B stick. We will need to solder either jumper wires or header pins to the pads.
313
313
{: .fs-1 }
314
314
@@ -413,7 +413,7 @@ void loop() {
413
413
414
414
If your colors look wrong (*e.g.,* you asked for red but got green), try changing `NEO_GRB` to `NEO_RGB` in the strip constructor. This is the most common issue students encounter!

417
417
**Figure.** An image of the RGB LED stick running the above code. You can also view and play with this on [Tinkercad](https://www.tinkercad.com/things/lSqArYGju94-neopixel-strip-8-static-rainbow). See our [RainbowStatic8.ino](https://github.com/makeabilitylab/arduino/blob/master/AddressableLEDs/NeoPixel/RainbowStatic8/RainbowStatic8.ino) and [RainbowStatic.ino](https://github.com/makeabilitylab/arduino/blob/master/AddressableLEDs/NeoPixel/RainbowStatic/RainbowStatic.ino) sketches in GitHub.
Copy file name to clipboardExpand all lines: advancedio/smoothing-input.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ usetocbot: true
23
23
24
24
By now, you may have noticed that your analog input data can be noisy. How can we smooth our input and what factors should we consider?
25
25
26
-
<videoautoplayloopmutedplaysinline>
26
+
<videoaria-label="A noisy analog input signal (blue) being smoothed in real time by a moving average filter with a window size of 10 (red), graphed in the Arduino Serial Plotter"autoplayloopmutedplaysinline>
@@ -52,7 +52,7 @@ When reading sensor data using analog input pins on a microcontroller (*e.g.,* v
52
52
53
53
Even with a simple potentiometer, we can observe noise on our input pin. In the video below, we are **not** touching the potentiometer and yet the analog input is oscillating between 142 and 143 (0.694V and 0.699V)—shown as the blue line. You may have experienced this too in your own potentiometer-based projects or in the [Arduino potentiometer lesson](../arduino/potentiometers.md). In this case, we fixed this "input noise" by smoothing the signal using a moving average filter—shown in red—which we will describe in this lesson.
54
54
55
-
<videoautoplayloopmutedplaysinline>
55
+
<videoaria-label="A potentiometer's raw analog input (blue) oscillating between 142 and 143 while untouched, with the noise removed by a moving average filter of window size 10 (red)"autoplayloopmutedplaysinline>
**Video.** In this video, we're graphing the raw analog input (blue line) from a potentiometer along with a "smoothed" version (red line). Although we're not touching or using the potentiometer, the analog input is oscillating between 142 and 143 (0.694V and 0.699V). We smooth this noise using a moving average filter (window size = 10)—shown in red. Note that, depending on the oscillation pattern, a different window size or smoothing approach may be necessary. Read more about potentiometer noise [here](https://passive-components.eu/resistors-potentiometers-basic-principles/). Graph made with the built-in [Arduino Serial Plotter](https://diyrobocars.com/2020/05/04/arduino-serial-plotter-the-missing-manual/).
@@ -92,7 +92,7 @@ This filter is a type of **low-pass** filter because it smooths out (eliminates)
92
92
93
93
You can control the filter's performance by tweaking the size of the sliding window. The animation below demonstrates a sliding window of size 3. The blue line corresponds to the raw input signal; the orange line, the smoothed filter output. For illustrative purposes, we only show the sliding window applied to a subset of data.
94
94
95
-
<videoautoplayloopmutedplaysinline>
95
+
<videoaria-label="An animation illustrating a moving average filter with a window size of 3 sliding over a raw input signal (blue) to produce the smoothed output (orange)"autoplayloopmutedplaysinline>
**Video** This video illustrates a moving average filter of window size 3 over a subset of data. Animation made in PowerPoint.
@@ -109,7 +109,7 @@ Below, we compute three different moving average filter window sizes: 5, 10, and
109
109
110
110
<!-- The object-oriented filtering approach makes it easy to test and compare the effect of different window sizes on the filtered output. -->
111
111
112
-
<videoautoplayloopmutedplaysinline>
112
+
<videoaria-label="Raw analog input (blue) graphed alongside moving average filter output for three window sizes: 5 (red), 10 (green), and 20 (yellow), in the Arduino Serial Plotter"autoplayloopmutedplaysinline>
**Video** This video graphs raw analog input (blue) and filtered output from three different moving average window sizes: 5 (red line), 10 (green), and 20 (yellow). To produce this video, we used [this code](https://github.com/makeabilitylab/arduino/blob/master/Filters/MovingAverageFilterWindowSizeDemo/MovingAverageFilterWindowSizeDemo.ino) and the [Arduino Serial Plotter](https://diyrobocars.com/2020/05/04/arduino-serial-plotter-the-missing-manual/). You should [try it](https://github.com/makeabilitylab/arduino/blob/master/Filters/MovingAverageFilterWindowSizeDemo/MovingAverageFilterWindowSizeDemo.ino) yourself!
@@ -190,7 +190,7 @@ Below, we've included sample weights for both linear and exponential weighting s
|||
194
194
| Linearly decreasing weights for window size 15 | Exponentially decreasing weights for window size 15|
195
195
196
196
**Figure.** Images from [Wikipedia](https://en.wikipedia.org/wiki/Moving_average).
@@ -217,7 +217,7 @@ Where:
217
217
218
218
The coefficient $$\alpha$$ determines the exponential dropoff. A higher $$\alpha$$ weights more recent data more. For example, the video below shows EWMA performance with $$\alpha$$ equal to 0.5 (red line), 0.1 (green line), and 0.01 (yellow line). Notice how closely the $$\alpha=0.5$$ EWMA filter tracks the underlying raw signal whereas the $$\alpha=0.01$$ filter is quite distorted and lagged. The $$\alpha=0.1$$ filter may still be appropriate, depending on your needs. Again, it's up to you to experiment!
219
219
220
-
<videoautoplayloopmutedplaysinline>
220
+
<videoaria-label="Exponentially weighted moving average filter output for three alpha values: 0.5 (red) tracking the raw signal closely, 0.1 (green), and 0.01 (yellow) heavily distorted and lagged"autoplayloopmutedplaysinline>
**Video** This video shows EWMA performance with $$\alpha$$ equal to 0.5 (red line), 0.1 (green line), and 0.01 (yellow line). The code used to produce this video is [here](https://github.com/makeabilitylab/arduino/blob/master/Filters/EwmaFilterAlphaDemo/EwmaFilterAlphaDemo.ino). Graph made with the built-in [Arduino Serial Plotter](https://diyrobocars.com/2020/05/04/arduino-serial-plotter-the-missing-manual/).
@@ -264,7 +264,7 @@ void loop()
264
264
265
265
A **moving median filter** is almost the exact same as a [moving average filter](#moving-average-filter) but takes the **median** over the sliding window rather than the average.
266
266
267
-
<videoautoplayloopmutedplaysinline>
267
+
<videoaria-label="An animation illustrating a moving median filter with a window size of three sliding over a signal to produce the smoothed output"autoplayloopmutedplaysinline>
**Video** This video shows a moving median filter with a window size of three. Animation made in PowerPoint.
@@ -295,7 +295,7 @@ But how can we obtain this "middle" value efficiently? We know that re-sorting a
295
295
296
296
Similar to the moving average filter, we can tweak the moving median filter's performance by modifying the filter window size. Below, we show a moving median filter with window sizes 5, 11, and 21. For this video, we used our test code [MovingMedianFilterWindowSizeDemo.ino](https://github.com/makeabilitylab/arduino/blob/master/Filters/MovingMedianFilterWindowSizeDemo/MovingMedianFilterWindowSizeDemo.ino), which relies on Luis Llama's [Arduino Median Filter 2](https://github.com/warhog/Arduino-MedianFilter) library based on Phil Ekstrom's "[Better Than Average](https://www.embedded.com/better-than-average/)" article.
297
297
298
-
<videoautoplayloopmutedplaysinline>
298
+
<videoaria-label="Moving median filter output for window sizes 5, 11, and 21, showing how the median filter flattens peaks in the signal, graphed in the Arduino Serial Plotter"autoplayloopmutedplaysinline>
**Video** This video shows moving median filter performance with window sizes 5, 11, and 21. Notice how a median filter tends to flatten "peaks" in the signal, which is unlike the other filters we've examined. To make this video, we used [this code](https://github.com/makeabilitylab/arduino/blob/master/Filters/MovingMedianFilterWindowSizeDemo/MovingMedianFilterWindowSizeDemo.ino) and the built-in [Arduino Serial Plotter](https://diyrobocars.com/2020/05/04/arduino-serial-plotter-the-missing-manual/).
@@ -305,7 +305,7 @@ Similar to the moving average filter, we can tweak the moving median filter's pe
305
305
306
306
Median filters are widely used in image processing to remove noise from images (image processing is its own subfield of signal processing focusing on 2D DSP techniques). Unlike mean (or average) filters, median filters remove noise while preserving edges—and edges are often a crucial part of other image processing algorithms like the [Canny edge detector](https://en.wikipedia.org/wiki/Canny_edge_detector).
307
307
308
-

308
+

309
309
{: .mx-auto .align-center }
310
310
311
311
**Figure**. Median filtering is widely used in image processing where it is particularly effective at removing "speckle" or "salt-and-pepper" noise while preserving edges. Image from [Wikipedia](https://en.wikipedia.org/wiki/Median_filter).
@@ -315,7 +315,7 @@ In the case of 1-dimensional signal processing, which we've focused on in this l
|||
319
319
| The moving average filter distorts the rising and falling edges of the clock signal | The median filter both smooths the signal and crispens the clock transition edges |
320
320
321
321
**Figure.** Images from [MathWorks](https://www.mathworks.com/help/signal/ug/signal-smoothing.html).
<iframetitle="Workbench video of an Arduino blinking multiple LEDs at different rates without using delay()"src="https://www.youtube.com/embed/8DHhmXr3mC8"frameborder="0"allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"allowfullscreen></iframe>
215
215
</div>
216
216
217
217
### Multi-rate blinking: an object-oriented approach
@@ -326,7 +326,7 @@ See the [code in our GitHub repository](https://github.com/makeabilitylab/arduin
<iframetitle="Workbench video of multi-rate LED blinking using the Blinker class in external .h and .cpp files"src="https://www.youtube.com/embed/vb5l8Tncedo"frameborder="0"allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"allowfullscreen></iframe>
Copy file name to clipboardExpand all lines: arduino/rgb-led-fade.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,13 +147,13 @@ This [source code](https://github.com/makeabilitylab/arduino/blob/master/Basics/
147
147
Here are two videos showing the code running on an Arduino Uno. First, in the Tinkercad simulator. You can see the crossfade colors and a plot of the corresponding `analogWrite` values.
<iframetitle="Tinkercad simulation of the RGB crossfader code with a plot of the corresponding analogWrite values"src="https://www.youtube.com/embed/ZyfHRQFwmeg"frameborder="0"allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"allowfullscreen></iframe>
151
151
</div>
152
152
153
153
Second, a workbench video of the code running on an Arduino Uno:
<iframetitle="Workbench video of the RGB crossfader code running on an Arduino Uno"src="https://www.youtube.com/embed/zL7xIWHqVaY"frameborder="0"allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"allowfullscreen></iframe>
157
157
</div>
158
158
159
159
<!--TODO: add in a p5js that demonstrates how this works? And maybe let's reader play with different color values? -->
@@ -169,7 +169,7 @@ RGB and HSL color space visualizations from [Wikipedia](https://en.wikipedia.org
169
169
Here's a video of various hues, saturations, and lightness levels using Hunor Marton's HSL Color Picker. Play around with it yourself on [codepen.io](https://codepen.io/HunorMarton/pen/dvXVvQ/). You can also open up almost any painting or graphics application to play with and switch between colorspaces from MSPaint to Adobe Photoshop and Illustrator to [GIMP](https://www.gimp.org/) and [Inkscape](https://inkscape.org/).
<iframetitle="Screen recording of Hunor Marton's HSL Color Picker showing various hues, saturations, and lightness levels"src="https://www.youtube.com/embed/a0j8qyBJE2E"frameborder="0"allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"allowfullscreen></iframe>
173
173
</div>
174
174
A screen recording of [Hunor Marton's HSL Color Picker](https://codepen.io/HunorMarton/pen/dvXVvQ/).
175
175
{: .fs-1 }
@@ -225,7 +225,7 @@ This [source code](https://github.com/makeabilitylab/arduino/blob/master/Basics/
225
225
Here's a workbench video of [CrossFadeHue.ino](https://github.com/makeabilitylab/arduino/tree/master/Basics/analogWrite/CrossFadeHue) with a common cathode RGB LED.
<iframetitle="Workbench video of the HSL-based RGB crossfader (CrossFadeHue.ino) running on a common cathode RGB LED"src="https://www.youtube.com/embed/ROfJge7bsfI"frameborder="0"allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"allowfullscreen></iframe>
229
229
</div>
230
230
231
231
<!-- TODO look up what the minimum step value that makes sense with our quantization -->
Copy file name to clipboardExpand all lines: arduino/rgb-led.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -185,14 +185,14 @@ That's it. Now compile, upload, and run your code!
185
185
In the video below, I'm running our [BlinkRGB](https://github.com/makeabilitylab/arduino/tree/master/Basics/digitalWrite/BlinkRGB) code, which is the same as above but includes some [`Serial.print`](https://www.arduino.cc/reference/en/language/functions/communication/serial/print/) calls for debugging (see this [mini-tutorial](https://create.arduino.cc/projecthub/glowascii/serial-monitor-arduino-basics-399eb6) on using the Serial.print and the Arduino IDE's Serial Monitor for debugging)
<iframetitle="Workbench video of the BlinkRGB code cycling a common cathode RGB LED through colors, diffused by a yogurt container"src="https://www.youtube.com/embed/ASez28rPjRU"frameborder="0"allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"allowfullscreen></iframe>
189
189
</div>
190
190
The yogurt container is used to diffuse the light. Kleenex, white paper, or a ping pong ball (with a hole in it for the LED) works well too!
191
191
{: .fs-1 }
192
192
193
193
Below, we show a video animation of the code executing and resulting circuit behavior. Pay close attention to the direction of current—it will flow in the opposite direction with the Common Anode design (covered next).
194
194
195
-
<videocontrols="controls">
195
+
<videoaria-label="Animation of a common cathode RGB LED circuit executing, showing the direction of current flow"controls="controls">
@@ -249,7 +249,7 @@ We will flash the same sequence as before but again our `HIGH`s and `LOW`s are f
249
249
250
250
Here's an animation. Pay close attention to the current direction—it flows from 5V down through the LED, the current limiting resistors, and into the digital I/O pins.
251
251
252
-
<videocontrols="controls">
252
+
<videoaria-label="Animation of a common anode RGB LED circuit with current flowing from 5V down through the LED and resistors into the digital I/O pins"controls="controls">
0 commit comments