Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int buttonPin = 2;
- const int ledPin0 = 13; //green light
- const int ledPin1 = 12; //yellow light
- const int ledPin2 = 11; //red light
- int count = 0;
- // variables will change:
- int buttonState = 0;
- void setup() {
- pinMode(ledPin0, OUTPUT);
- pinMode(ledPin1, OUTPUT);
- pinMode(ledPin2, OUTPUT);
- pinMode(buttonPin, INPUT);
- }
- void loop(){
- buttonState = digitalRead(buttonPin);
- if (buttonState == HIGH) {
- count++;
- if (count >= 4) {
- count = 0;
- }
- }
- else {
- digitalWrite(ledPin0, LOW);
- digitalWrite(ledPin1, LOW);
- digitalWrite(ledPin2, LOW);
- }
- if (count == 1) {
- digitalWrite(ledPin0, HIGH);
- }
- else {
- digitalWrite(ledPin0, LOW);
- }
- if (count == 2) {
- digitalWrite(ledPin1, HIGH);
- }
- else {
- digitalWrite(ledPin1, LOW);
- }
- if (count == 3) {
- digitalWrite(ledPin2, HIGH);
- }
- else {
- digitalWrite(ledPin2, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement