Count Sketch w/ Semi-button
AHHHH. ok. So, this code will blink up to 5 when button is pressed. When up to 5, we can't get it turn off with a button, but it'll do it automatically.. We will keep working on the forloop. More updates this weekend.
/*
Blinks count to 5
Kristina - Karin
*/
int buttonPin = 2; // the number of the pushbutton pin
int led = 13; // LED connected
int val = 0;
int state = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
val = digitalRead(buttonPin); // turn count on
if (val == HIGH) {
//ONE
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(300); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1300); // wait for a second
//TWO
digitalWrite(led, HIGH); // one
delay(300); //wait
digitalWrite(led, LOW); // off
delay(300); //wait
digitalWrite(led, HIGH); // two
delay(300); //wait
digitalWrite(led, LOW); // off
delay(1300); //wait
//THREE
digitalWrite(led, HIGH); // one
delay(300); //wait
digitalWrite(led, LOW); // off
delay(300); //wait
digitalWrite(led, HIGH); // two
delay(300); //wait
digitalWrite(led, LOW); // off
delay(300); //wait
digitalWrite(led, HIGH); //three
delay(300); //wait
digitalWrite(led, LOW); // off
delay(1300); //wait
//FOUR
digitalWrite(led, HIGH); // one
delay(300); //wait
digitalWrite(led, LOW); // off
delay(300); //wait
digitalWrite(led, HIGH); // two
delay(300); //wait
digitalWrite(led, LOW); // off
delay(300); //wait
digitalWrite(led, HIGH); // three
delay(300); //wait
digitalWrite(led, LOW); // off
delay(300); //wait
digitalWrite(led, HIGH); //four
delay(300); //wait
digitalWrite(led, LOW); // off
delay(1300); //wait
//FIVE
digitalWrite(led, HIGH); // one
delay(300); //wait
digitalWrite(led, LOW); // off
delay(300); //wait
digitalWrite(led, HIGH); // two
delay(300); //wait
digitalWrite(led, LOW); // off
delay(300); //wait
digitalWrite(led, HIGH); // three
delay(300); //wait
digitalWrite(led, LOW); // off
delay(300); //wait
digitalWrite(led, HIGH); //four
delay(300); //wait
digitalWrite(led, LOW); // off
delay(300); //wait
digitalWrite(led, HIGH); //five
delay(300); //wait
digitalWrite(led, LOW); // off
delay(1300); //wait
}
}
Sometimes we get this error message when we plug the arduino into either of our computers and we are unsure what exactly is causing it:
Here's our set-up:
Hmmm. this "too much power" issue has hapened to me before. Let's check this out in class tomorrow.
ReplyDeleteAs for the button killing the loop, we need to set a "check variable" somewhere, and run the loop (the counting) only while 1)count is not reached at 5 and 2)check var is not true.
let's talk this through in class also.