Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int led = 13;
- int led1 = 12;
- int led2 = 11;
- int led3 = 10;
- int led4 = 9;
- int led5 = 8;
- int led6 = 7;
- int switchUpPin = 2;
- int switchDownPin = 3;
- int counter = 0;
- int counter1 = 0;
- int buttonUpState = 0;
- int lastButtonUpState = 0;
- int buttonDownState = 0;
- int lastButtonDownState = 0;
- int buttonUpState1 = 0;
- int lastButtonUpState1 = 0;
- int buttonUpState2 = 0;
- int lastButtonUpState2 = 0;
- void setup()
- {
- Serial.begin(9600);
- pinMode(led, OUTPUT);
- pinMode(led1, OUTPUT);
- pinMode(led2, OUTPUT);
- pinMode(led3, OUTPUT);
- pinMode(led4, OUTPUT);
- pinMode(led5, OUTPUT);
- pinMode(led6, OUTPUT);
- }
- void loop()
- {
- buttonUpState = digitalRead(switchUpPin);
- buttonDownState = digitalRead(switchDownPin);
- if (buttonUpState != lastButtonUpState)
- {
- if (buttonUpState == HIGH)
- {
- if(counter == 9)
- {
- counter = -1;
- }
- counter++;
- Serial.println(counter);
- changeNumber(counter);
- delay(300);
- }
- else
- {
- Serial.println("OFF");
- }
- delay(50);
- }
- if (buttonDownState != lastButtonDownState)
- {
- if (buttonDownState == HIGH)
- {
- if(counter == 0)
- {
- counter = 10;
- }
- counter--;
- Serial.println(counter);
- changeNumber(counter);
- delay(300);
- }
- else
- {
- Serial.println("OFF");
- }
- delay(50);
- }
- changeNumber(counter);
- }
- void changeNumber(int buttonPress)
- {
- switch (buttonPress)
- {
- //number 0
- case 0:
- digitalWrite(led, HIGH);
- digitalWrite(led1, HIGH);
- digitalWrite(led2, LOW);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- digitalWrite(led5, HIGH);
- digitalWrite(led6, HIGH);
- break;
- //number 1
- case 1:
- digitalWrite(led, HIGH);
- digitalWrite(led1, HIGH);
- digitalWrite(led2, LOW);
- digitalWrite(led3, LOW);
- digitalWrite(led4, LOW);
- digitalWrite(led5, LOW);
- digitalWrite(led6, LOW);
- break;
- //number 2
- case 2:
- digitalWrite(led, HIGH);
- digitalWrite(led1, LOW);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, LOW);
- digitalWrite(led5, HIGH);
- digitalWrite(led6, HIGH);
- break;
- //number 3
- case 3:
- digitalWrite(led, HIGH);
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, LOW);
- digitalWrite(led5, HIGH);
- digitalWrite(led6, LOW);
- break;
- //number 4
- case 4:
- digitalWrite(led, HIGH);
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, LOW);
- digitalWrite(led4, HIGH);
- digitalWrite(led5,LOW);
- digitalWrite(led6, LOW);
- break;
- //number 5
- case 5:
- digitalWrite(led, LOW);
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- digitalWrite(led5, HIGH);
- digitalWrite(led6, LOW);
- break;
- //number 6
- case 6:
- digitalWrite(led, LOW);
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- digitalWrite(led5,HIGH);
- digitalWrite(led6, HIGH);
- break;
- //number 7
- case 7:
- digitalWrite(led, HIGH);
- digitalWrite(led1, HIGH);
- digitalWrite(led2, LOW);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, LOW);
- digitalWrite(led5,LOW);
- digitalWrite(led6, LOW);
- break;
- //number 8
- case 8:
- digitalWrite(led, HIGH);
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- digitalWrite(led5,HIGH);
- digitalWrite(led6, HIGH);
- break;
- //number 9
- case 9:
- digitalWrite(led, HIGH);
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- digitalWrite(led5,HIGH);
- digitalWrite(led6, LOW);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement