mardi 5 mai 2015

Using button to change LED states

I'm trying to make a program with Arduino Uno which uses a button and two LEDs.

I'd like the button to act as the switch for the different lightpatterens of the LEDs but instead of being in a state until the button is pressed the program just goes through all the patterns and then stops.

int ledDelay = 100; // delay by 50ms

int redPin = 11; //choose input for LED
int greenPin = 9; //choose input for LED
int inPin = 7; //choose input for button
int count = 0;
int inPinState = 0;


void setup() {

pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(inPin, INPUT);

}


void loop() {


if (digitalRead(inPinState == HIGH)) {
count++;
}

if (count == 4) {
count == 0;}



if (count == 0) {
**function 0**
}
delay(1000);

if (count == 1) {
**function 1**
}
delay(1000);

if (count == 2) {
**function 2**
}
delay(1000);

if (count == 3) {

**function 3**
}


}

Aucun commentaire:

Enregistrer un commentaire