PComp Final: Secondary feedback and moving forward!

So after much trial and error and lots and lots of discussion, I’ve decided to  keep it the 3 LEDs and style the pendant like a stop light. That being said, my next stop was to get a breadboard going with all the components to start the code and debug from there! So first was just the lights itself to test the circuit…

20161113_120048sm

And then added a switch!

20161113_124509sm

Taking a sample of the code from UKHeliBob here on the Arduino Forums HERE, and the State Change Detection code that comes with the Arduino IDE examples:

// this constant won’t change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int redLed = 3; // the pin that the LED is attached to
const int yellowLed = 4; // the pin that the LED is attached to
const int greenLed = 5; // the pin that the LED is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button

void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT); // set the switch pin to be an input
pinMode(yellowLed, OUTPUT); // set the yellow LED pin to be an output
pinMode(redLed, OUTPUT); // set the red LED pin to be an output
pinMode(greenLed, OUTPUT); //set green LED pin as output
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);

// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
switch (buttonPushCounter)
{

case 2: // no LEDs on
digitalWrite(redLed, HIGH); // turn on the red LED
buttonPushCounter++;
break;

case 3: //red LED is on
digitalWrite(yellowLed, HIGH); // turn on the yellow LED
buttonPushCounter++;
break;

case 4: //red & yellow LEDs are on
digitalWrite(greenLed, HIGH); // turn on the green LED
buttonPushCounter++;
break;

default: //all 3 LEDs are on
digitalWrite(yellowLed, LOW); // turn off the yellow LED
digitalWrite(redLed, LOW); // turn off the red LED
digitalWrite(greenLed, LOW); // turn off the green LED
buttonPushCounter++;

}

}
Serial.println(buttonPushCounter);

}

lastButtonState = buttonState;

}

It is still not working even with a half hour of office time with Benedetta (and both of us feeling under the weather to boot!), but we’re getting there. This week’s goal is to refine it and make time again  possibly to have a little jam session. Since it’s always nice to have another person look over your code!

As I do that I am trying to visualize the container I will need to fabricate for this and just keeping it into the back of my mind. I picked up a copy of Make: Wearable Electronics to give me some inspiration but all it is is giving me other ideas not related to this project…but possible future projects!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.