Challenge Name | Christmas Time |
Author | Kyle Chan |
Credit | I referenced the code off newinnovators.ca |
Difficulty Level (1-5) | 3 |
Time To Complete | 5 minutes |
Challenge Description | Pressing the button turns on off the green and turns on the red |
Hint | copy and paste really helps |
Answer | const int buttonPin1 = 2; const int buttonPin2 = 3; const int ledPin1 = 10; const int ledPin2 = 9; const int ledPin4 = 11; const int ledPin3 = 8; int buttonState1 = 0; int buttonState2 = 0; void setup() { pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); } void loop() { buttonState1 = digitalRead(buttonPin1); buttonState2 = digitalRead(buttonPin2); if (buttonState1 == HIGH) { digitalWrite(ledPin1, HIGH); digitalWrite(ledPin4, HIGH); delay(1000); digitalWrite(ledPin1, LOW); digitalWrite(ledPin4, LOW); } else if (buttonState2 == HIGH) { digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, HIGH); delay(1000); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); } } |
Tuesday, 24 November 2015
Challenge 3 - Button Control
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment