Bike Light

Our project is making
a bike light. This bike light changes from off to on to blinking to
alternating lights in order. The way to change the lights and what they
do is to press a button.

Our project sets up
five leds and a push button on an arduino breadboard. We set up the 6
things as pinmodes. The five lights as outputs and the push button as an
input. The setup starts at 0 and every time you press and release the push
button, it goes up until 3 then turns back to zero. The first mode is off
when the value is at zero. The second mode is all on when the value is at
one. The third value is blinking when the value is at two. The
fourth value is alternating when the value is at three. The project
involves things we learned in chapters 4 and 5.

val2 =
digitalRead(switchPin); // read the input again to check for
bounces

if (val ==
val2) { // make sure we
got 2 consistant readings

if (val
!= buttonState) { // the button state has
changed

if (val == LOW) { //
check if the button is pressed

if (lightMode == 0) { // if its off

lightMode = 1;
// turn lights on!

} else {

if (lightMode == 1) { // if its all-on

lightMode = 2;
// make it blink

} else {

if (lightMode == 2) { // if its
blinking

lightMode = 3;
// make it alternate

} else {

if (lightMode ==
3) { // if its waving,

lightMode = 0;
// turn light off

}

}

}

}

}

}

buttonState = val; //
save the new state in our variable

}

// Now do
whatever the lightMode indicates

if (lightMode
== 0) { // all-off

digitalWrite(led1Pin, LOW);

digitalWrite(led2Pin, LOW);

digitalWrite(led3Pin, LOW);

digitalWrite(led4Pin, LOW);

digitalWrite(led5Pin, LOW);

}

if (lightMode
== 1) { // all-on

digitalWrite(led1Pin, HIGH);

digitalWrite(led2Pin, HIGH);

digitalWrite(led3Pin, HIGH);

digitalWrite

led4Pin, HIGH);

digitalWrite(led5Pin, HIGH);

}

if (lightMode == 2) { // blinking

digitalWrite(led1Pin, HIGH);

digitalWrite(led2Pin, HIGH);

digitalWrite(led3Pin, HIGH);

digitalWrite(led4Pin, HIGH);

digitalWrite(led5Pin, HIGH);

delay(100);

digitalWrite(led1Pin, LOW);

digitalWrite(led2Pin, LOW);

digitalWrite(led3Pin,
LOW);

digitalWrite(led4Pin, LOW);

digitalWrite(led5Pin, LOW);

delay(100);

}

if (lightMode
== 3) { // alternate

digitalWrite(led5Pin, LOW);

digitalWrite(led1Pin, HIGH);

delay(50);

digitalWrite(led1Pin, LOW);

digitalWrite(led2Pin,
HIGH);

delay(50);

digitalWrite(led2Pin, LOW);

digitalWrite(led3Pin, HIGH);

delay(50);

digitalWrite(led3Pin, LOW);

digitalWrite(led4Pin, HIGH);

delay(50);

digitalWrite(led4Pin, LOW);

digitalWrite(led5Pin, HIGH);

delay(50);

digitalWrite(led5Pin, LOW);

}

}

Some problems we faced were getting the alternating lights to light up in the
right order. We finally discovered how to finish the project.
Another problem was setting up the push button but we figured that out.

We would have added
more lights and made a stable place to put the lights if we had more time.