Binary Red/Green Snippet

One step closer…

Switch open yields a killer red LED…


Switch closed yields an uber-sexy green LED…


I even tossed in some 1K resistors to keep my LEDs healthy, in addition to my 100 ohm / 10000 ohm pull-down setup.

+4 resistor

I even managed to comment my code, for a bonus win:

* binary red/green led setup
* by Joseph Swanson

int led1 = 11; // green LED (pin 11)
int led2 = 12; // red LED (pin 12)
int swit= 5; // switch (pin 5)
int varr; // to read pin on/off (pin 5)

void setup() {
pinMode(led1, OUTPUT); // output green
pinMode(led2, OUTPUT); // output red
pinMode(swit, INPUT); // switch input

void loop(){
varr = digitalRead(swit); // store swit to varr
if (varr == LOW) { // button = pressed
digitalWrite(led1, HIGH); // trigger green
digitalWrite(led2, LOW); // ground red
if (varr == HIGH) { // button != pressed
digitalWrite(led1, LOW); // ground green
digitalWrite(led2, HIGH); // trigger red

+1 Snippet

I’m getting closer to having this thing behave the way I intend. Stay tuned for a while longer. I’ll have a robot up and rolling in no time whatsoever.

Pull Down Switch Arduino *Fun

Maybe Vegas got the best of me, brain-wise. I’m struggling mightily with this pull-down switch prototype on my Arduino. I got it, after far-too-much troubleshooting.

pull down
maxxximum powwwwer

Maybe I need another frozen slushy drink. Or alternatively, a supplementary OML to get me through this…the end goal is to get some logic incorporated to ‘read’ the state of the switch, so that I don’t need my finger on the sonofabitch to keep the light lit. Or lighted…getting tired here.

Stay tuned. I’ll get this knocked out.