Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define button 3
- #define buttonUp 4
- #define buttonDown 5
- #define relay 8
- int Hours=0;
- int Min=0;
- boolean buttonPress = false ,bt_state = false ,longPress = false ;
- long timerStart;
- const long delay_long_press = 500;
- const long delay_short_press = 270;
- long lastDebounceTime = 0;
- int x =0;
- void setup()
- {
- // Serial.begin(9600);
- pinMode(button,INPUT);
- pinMode(buttonUp,INPUT);
- pinMode(buttonDown,INPUT);
- pinMode(relay,OUTPUT);
- }
- void loop()
- {
- if(digitalRead(button) == HIGH)
- {
- if (buttonPress == false)
- {
- buttonPress = true ;
- timerStart = millis();
- }
- if((millis() - timerStart > delay_long_press) && (longPress == false)) // check for long press
- {
- longPress = true ;
- bt_state = !bt_state;
- }
- }
- else
- {
- if (buttonPress == true)
- {
- if (longPress == true)
- {
- longPress = false ;
- }
- buttonPress = false ;
- }
- }
- if(bt_state == true)
- {
- if ((millis() - lastDebounceTime) > delay_short_press) // debounce for one press
- {
- if (digitalRead(button) == HIGH && buttonPress == true)
- {
- x++;
- if(x > 2)
- {
- x = 0 ;
- }
- }
- adjust_time(x);
- lastDebounceTime = millis();
- }
- }
- }
- void adjust_time(int menu_place)
- {
- switch(menu_place)
- {
- case 1:
- if (digitalRead(buttonUp) == HIGH)
- {
- Hours++;
- }
- if (digitalRead(buttonDown) == HIGH)
- {
- Hours--;
- }
- break;
- case 2:
- if (digitalRead(buttonUp) == HIGH)
- {
- Min++;
- }
- if (digitalRead(buttonDown) == HIGH)
- {
- Min--;
- }
- break;
- }
- }
Add Comment
Please, Sign In to add comment