Tuesday, January 20, 2009

Week 2 - Circuitry and Conductive Material

This week we had a review on the circuitry of Arduino and digital input.
The digital input we had was a push button, where in the example code if we pushed the button the LED will light up and when we released the button, it turns off.

From that we were suppose to edit the code so that there are different modes for the lights to turn on. Our team's code gave the LED 3 different modes. OFF, Blinking, and ON.
The code is as follows:

int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int mode = 0;
boolean press;
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
}

void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
press = true;
if (mode == 0) {
digitalWrite(ledPin, LOW); // turn LED ON
}

else if (mode == 1) {
digitalWrite(ledPin, LOW); // turn LED ON
delay(500);
digitalWrite(ledPin, HIGH); // turn LED ON
delay(500);

}
else if (mode == 2) {
digitalWrite(ledPin, HIGH); // turn LED OFF
}
}

else {
if (press == true) {
press = false;
digitalWrite(ledPin, LOW); // turn LED ON
mode += 1;
if (mode == 3) {
mode = 0;
}
}
}
}

As for the lab assignment we are trying to make a bracelet using the same concept.
//FASTER BLINKING Mode
//----------------------------
else if (mode == 2) {
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW); // turn LED OFF
delay(200);

}

//2 FAST BLINKS, 3 FASTER BLINKS Mode
//--------------------------------------------
else if (mode == 3) {
digitalWrite(ledPin, HIGH); // turn LED ON
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH); // turn LED ON
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH); // turn LED ON
delay(50);
digitalWrite(ledPin, LOW);
delay(50);
digitalWrite(ledPin, HIGH); // turn LED ON
delay(50);
digitalWrite(ledPin, LOW);
delay(50);
digitalWrite(ledPin, HIGH); // turn LED ON
delay(50);
digitalWrite(ledPin, LOW);
delay(50);

}

// "And the screen went
BeepBeepBeepBeepBeepBeep!" Mode
else if (mode == 4) {
digitalWrite(ledPin, HIGH); // turn LED OFF
delay(50);
digitalWrite(ledPin, LOW);
delay(50);
}

(Input IMAGE HERE)

The code remained pretty much the same except for 3 added modes and the LEDs are connected through parallel in Pin 13. Also the LEDs are copper taped onto the felt and a button is sewed in.
However, we do notice that sometimes the connection is weak.



No comments:

Post a Comment