Digital I/O

Part 1:

“Solder a circuits from Monday to a prototyping board (2 leds in series or parallel).”

For part one, I remade my in series circuit by soldering all the components to a small perf board.  The result was a cute little breakout board with three tiny green LEDs, one 100 Ω resistor and a tiny button.  Simple but useful

This slideshow requires JavaScript.

Part 2:

“Build a circuit with 2 or more digital inputs. Use LEDs (regular or RGB) or neopixels as outputs. Program your microcontroller so that each input has a unique output.”

Parts: micro-controller, breadboard, neopixel strip, button, switch, LED, resistors.  

My idea was to have a circuit that has an “on/off” toggle switch and a button that, when pressed, lights up a green LED and changes the light animation from  slow blinking blues and purples (Chill mode) to brighter flashing reds and yellows (Burn mode) on a neopixel strip.

IMAG1241.jpg
schematic showing hook up of micro-controller, two switches, one LED, and a short RGB LED neopixel strip.

I had a bit of trouble getting the buttons to work at first, but then our instructor pointed out I was missing part of the code.  After working out that hang up, I was able to get my light components up and running.  I like working with the ALA (Arduino Light Animation) Library.  This library has some nice “twinkly” options that I’ve really enjoyed using in other projects, and it is easy to add to the Arduino IDE.

Test of the button and toggle with green LED

IMAG1240.jpg

Here is the code:


#include <AlaLedRgb.h>
AlaLedRgb rgbStripChill;
AlaLedRgb rgbStripBurn;
AlaLedRgb rgbStripoff;
AlaSeq Burn[] =
{
{ ALA_OFF, 100, 100, alaPalNull },
{ ALA_FIRE, 1000, 6000, alaPalFire },
{ ALA_OFF, 100, 100, alaPalNull },
{ ALA_ENDSEQ }
};
AlaSeq Chill[] =
{
{ ALA_OFF, 100, 100, alaPalNull },
{ ALA_SPARKLE2, 1000, 6000, alaPalCool },
{ ALA_OFF, 100, 100, alaPalNull },
{ ALA_ENDSEQ }
};
AlaSeq off[] =
{
{ ALA_OFF, 100, 100, alaPalNull },
{ ALA_ENDSEQ }
};
int buttonState;
int toggleState;
void setup()
{
Serial.begin(9600);
pinMode(3, INPUT);
pinMode(6, OUTPUT);
rgbStripBurn.initWS2812(5, 12);
rgbStripBurn.setBrightness(0x444444);
rgbStripBurn.setAnimation(Burn);
rgbStripChill.initWS2812(5, 12);
rgbStripChill.setBrightness(0x111111);
rgbStripChill.setAnimation(Chill);
rgbStripoff.initWS2812(5, 12);
rgbStripoff.setBrightness(0x000000);
rgbStripoff.setAnimation(off);
}
void loop()
{
buttonState = digitalRead(3);
toggleState = digitalRead(2);
Serial.print("button ");
Serial.println(buttonState);
Serial.print("toggle ");
Serial.println(toggleState);
if (toggleState == HIGH && buttonState == HIGH)
{digitalWrite(6, HIGH);
rgbStripBurn.runAnimation();
}
else if (toggleState == HIGH && buttonState == LOW)
{digitalWrite(6, LOW);
rgbStripChill.runAnimation();
}
else
{ Serial.print("off");
rgbStripoff.runAnimation();}
}

view raw

Object: LAB 2

hosted with ❤ by GitHub

Final video

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s