Skip to content

Harris Code

ThatGuyHarris2 edited this page Oct 11, 2017 · 1 revision

`int switchState = 0;

void setup() { // put your setup code here, to run once: pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(1, INPUT);

}

void loop() { // put your main code here, to run repeatedly: switchState = digitalRead(2);

//button not pressed if(switchState == LOW){ digitalWrite(3, HIGH); //red led digitalWrite(4, LOW); //green led digitalWrite(5, LOW); //green led } else{ //button is pressed digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, HIGH);

delay(250); //wait a quarter second
//toggle LEDs
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); //wait quarter second

} } //go back to beginning of loop`

Clone this wiki locally