Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int button = 6;
- int led1 = 5;
- int led2 = 4;
- int led3 = 3;
- int led4 = 2;
- bool isPressed;
- int counter = 0;
- void setup()
- {
- Serial.begin(9600);
- pinMode(button, INPUT);
- pinMode(led1, OUTPUT);
- pinMode(led2, OUTPUT);
- pinMode(led3, OUTPUT);
- pinMode(led4, OUTPUT);
- }
- void loop()
- {
- isPressed = digitalRead(button);
- if(isPressed == true){
- counter++;
- }
- Serial.println(counter);
- counter = counter % 16;
- if(counter == 1){
- digitalWrite(led1, LOW);
- digitalWrite(led2, LOW);
- digitalWrite(led3, LOW);
- digitalWrite(led4, HIGH);
- }
- if(counter == 2){
- digitalWrite(led1, LOW);
- digitalWrite(led2, LOW);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, LOW);
- }if(counter == 3){
- digitalWrite(led1, LOW);
- digitalWrite(led2, LOW);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- }
- if(counter == 4){
- digitalWrite(led1, LOW);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, LOW);
- digitalWrite(led4, LOW);
- }
- if(counter == 5){
- digitalWrite(led1, LOW);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, LOW);
- digitalWrite(led4, HIGH);
- }
- if(counter == 6){
- digitalWrite(led1, LOW);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, LOW);
- }if(counter == 7){
- digitalWrite(led1, LOW);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- }
- if(counter == 8){
- digitalWrite(led1, HIGH);
- digitalWrite(led2, LOW);
- digitalWrite(led3, LOW);
- digitalWrite(led4, LOW);
- }
- if(counter == 9){
- digitalWrite(led1, HIGH);
- digitalWrite(led2, LOW);
- digitalWrite(led3, LOW);
- digitalWrite(led4, HIGH);
- }
- if(counter == 10){
- digitalWrite(led1, HIGH);
- digitalWrite(led2, LOW);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, LOW);
- }if(counter == 11){
- digitalWrite(led1, HIGH);
- digitalWrite(led2, LOW);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- }
- if(counter == 12){
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, LOW);
- digitalWrite(led4, LOW);
- }
- if(counter == 13){
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, LOW);
- digitalWrite(led4, HIGH);
- }
- if(counter == 14){
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, LOW);
- }if(counter == 15){
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- }
- delay(400);
- // I put delay(400), because I don't want the counter to be
- // increased so quickly, so I suppose that the user presses
- // the button with max "duration" = 400ms
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement