Arduino: LED Twinkler: Basic Analog Input, Digital Output, PWM
The Arduino is a flexible platform for controlling all kinds of devices from all kinds of input signals. Here I demonstrate the most basic Analog Input — a voltage from a potentiometer — and use it to control the most basic Digital outputs — the behaviour of some LEDs connected to the Digital IO pins of the Arduino Uno.
Program sketches appear at the very end of the video. Watch in HD, fullscreen, pause and copy. You will learn much more by transcribing yourself than by copy-paste from a file!
ERRATA: In the second program sketch, TKFaderTester1, in setup() the “n=1” should be “n=0”. Arrays are zero-indexed in c++. The sketch works anyway, for some reason, but this should be corrected if anyone uses the program. I got it right in the loop() portion of the sketch.
In the last sketch, TKTwinkler1, in loop(), the “analogRead(2)” should be “analogRead(potPin)”. Again, the sketch works anyway because of the way the while loop works.
Some of the basic programming features illustrated:
— reading an analog input
— mapping the analog value to an arbitrary range of values
— looping through an array
— the “while” loop to switch between major program segments based on analog input
— testing if an input parameter has changed
— controlling the Arduino’s Digital outputs to switch LEDs (or other external loads)
— controlling the Arduino’s PWM outputs to vary brightness of LEDs, or vary external load current through a transistor
— combining segments of programs to make new programs