Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool lastButtonState;
- const int buttonPin = 2;
- const int buttonPin1 = 3;
- const int ledPin0 = 13; //green light
- const int ledPin1 = 12; //yellow light
- const int ledPin2 = 11; //red light
- int buttonState = 0;
- int buttonState1 = 0;
- int startPressed = 0;
- int endPressed = 0;
- int holdTime = 0;
- int idleTime = 0;
- int count = 0;
- void setup() {
- Serial.begin(9600);
- pinMode(ledPin0, OUTPUT);
- pinMode(ledPin1, OUTPUT);
- pinMode(ledPin2, OUTPUT);
- pinMode(buttonPin, INPUT);
- pinMode(buttonPin1, INPUT);
- }
- void loop(){
- buttonState = digitalRead(buttonPin);
- if (buttonState == HIGH && lastButtonState == LOW) {
- lastButtonState = buttonState;
- count++;
- if (count >= 19) {
- count = 0;
- }
- }
- else {
- lastButtonState = buttonState;
- digitalWrite(ledPin0, LOW);
- digitalWrite(ledPin1, LOW);
- digitalWrite(ledPin2, LOW);
- }
- if (count == 1) {
- digitalWrite(ledPin0, HIGH);
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- }
- if (count == 2) {
- digitalWrite(ledPin0, HIGH);
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- } if (count == 3) {
- digitalWrite(ledPin0, HIGH);
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- } if (count == 4) {
- digitalWrite(ledPin0, HIGH);
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- } if (count == 5) {
- digitalWrite(ledPin0, HIGH);
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- } if (count == 6) {
- digitalWrite(ledPin0, HIGH);
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- }
- else {
- digitalWrite(ledPin0, LOW);
- digitalWrite(ledPin1, LOW);
- digitalWrite(ledPin2, LOW);
- }
- if (count == 7) {
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- }
- if (count == 8) {
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- } if (count == 9) {
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- } if (count == 10) {
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- } if (count == 11) {
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- } if (count == 12) {
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
- }
- else {
- digitalWrite(ledPin1, LOW);
- digitalWrite(ledPin2, LOW);
- }
- if (count == 13) {
- digitalWrite(ledPin2, HIGH);
- }
- if (count == 14) {
- digitalWrite(ledPin2, HIGH);
- } if (count == 15) {
- digitalWrite(ledPin2, HIGH);
- } if (count == 16) {
- digitalWrite(ledPin2, HIGH);
- } if (count == 17) {
- digitalWrite(ledPin2, HIGH);
- } if (count == 18) {
- digitalWrite(ledPin2, HIGH);
- }
- else {
- digitalWrite(ledPin2, LOW);
- }
- }
- buttonState1 = digitalRead(buttonPin1);
- if (buttonState1 != lastButtonState) {
- updateState();
- }
- lastButtonState = button State1;
- }
- void updateState() {
- if (buttonState1 == HIGH) {
- startPressed = millis();
- idleTime = startPressed - endPressed;
- } else {
- endPressed = millis();
- holdTime = endPressed - startPressed;
- if (holdTime >= 1000) {
- Serial.println("UwU");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement