Advertisement
Guest User

HoldButton

a guest
Jan 22nd, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   https://playground.arduino.cc/Code/HoldButton
  3. */
  4.  
  5. void setup() {
  6.  
  7. }
  8. int RA8875_INT = 10;
  9. int buttonhoch = LOW;
  10. int buttonrunter = LOW;
  11. int buttonlinks = LOW;
  12. int buttonrechts = LOW;
  13. int menuchoice = 0;
  14. int uhrstunde = 0;
  15. int uhrminute = 0;
  16. int timerminute = 0;
  17. int timersekunde = 0;
  18. int timeredittoggle = 0;
  19. int timeredit = 0;
  20. int timereditdigit = 0; //1-4
  21. int digitplace[4] = {50, 100, 150, 200};
  22. int setdigithelper = LOW;
  23. int ledState[4] = {LOW, LOW, LOW, LOW};          // ledState used to set the LED
  24. int buttonwait = 1000;
  25. int buttonpin = 15;
  26. int menu = 0; //0=timer 1=clock
  27. boolean button_press = false;
  28. // Generally, you should use "unsigned long" for variables that hold time
  29. unsigned long previousMillis[6] = {500, 500, 500, 500, 500, 500};   // will store last time LED was updated
  30. unsigned long currentMillis = millis();
  31. // constants won't change:
  32. const long interval[6] = {1000, 1000, 1000, 1000, 1000, 1000};
  33. //Menü  1x kurz =Uhr/Timer.. 1x Lang = Uhr/Timer stellen Uhr->/Sommer/Winterzeit
  34. //menuchoice: 0=Uhr, 1=Timer 2=menu (5Sekunden drücken.. Uhr stellen, Sommerzeit)
  35. void loop() {
  36.   currentMillis = millis();
  37.   checkBlinking();
  38.   //switchmenuchoice();
  39.   int countspeed = 0;
  40.  
  41.   if (menu == 1) {
  42.  
  43.   }
  44.   switch (menuchoice) {
  45.     case 1:
  46.       //Screen clear
  47.       //4 Optionen geviertelt/halbiert
  48.       //
  49.       break;
  50.     default: ; break;
  51.   }
  52.  
  53. }
  54. void checkBlinking() {
  55.   if (currentMillis - previousMillis[0] >= interval[0]) {
  56.     previousMillis[0] = currentMillis;
  57.     timeredit = !timeredit;
  58.     if (setdigithelper == LOW)
  59.     {
  60.       timeredit == LOW; setdigithelper = HIGH;
  61.     }
  62.     if (timeredit == LOW) {
  63.       //Paint zahl timereditdigit digitplace
  64.     } else {
  65.       //Paint Black Space timereditdigit
  66.     }
  67.   }
  68.  
  69. }
  70.  
  71. void switchmenuchoice() {
  72.   if (currentMillis - previousMillis[1] >= interval[1]) {
  73.     previousMillis[1] = currentMillis;
  74.     timeredit = !timeredit;
  75.     if (menuchoice == 0) {
  76.       menuchoice = 1;
  77.       //Uhr
  78.     } else {
  79.       menuchoice = 0;
  80.       //Timer
  81.     }
  82.   }
  83. }
  84. int button = 0;
  85. int helpinterval = 1000;
  86. void longhold() {
  87.   if (currentMillis - previousMillis[2] >= interval[2]) {
  88.     previousMillis[2] = currentMillis;
  89.     timeredit = !timeredit;
  90.     if (menuchoice == 0) {
  91.       menuchoice = 1;
  92.       //Paint zahl timereditdigit digitplace
  93.     } else {
  94.       menuchoice = 0;
  95.       //Paint Black Space timereditdigit
  96.     }
  97.   } else if (button == LOW) {
  98.     previousMillis[2] = currentMillis;
  99.     interval[2] - 100 ;
  100.   }
  101. }
  102. int countwait = 1000;
  103. void hold_button() {
  104.   if(buttonpin == LOW ){
  105.   if ( currentMillis - previousMillis[3] >= interval[3])
  106.   {
  107.     if (currentMillis - previousMillis[4] >= interval[4]) {
  108.       previousMillis[4] = currentMillis;
  109.       button_press = true;
  110.     } else {
  111.       previousMillis[4] = currentMillis;
  112.     }
  113.    
  114.   }else{
  115.     button_press = false;
  116.    
  117.   }
  118. }else button_press = false;
  119. }
  120.  
  121. void countspeed() {
  122.   if (button_press)
  123.     if (currentMillis - previousMillis[5] >= countwait) {
  124.       previousMillis[5] = currentMillis;
  125.     }
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement