Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1.  
  2.  
  3. define LED1 1
  4. define LED2 2
  5. define LED3 3
  6. define LED4 4
  7. define LED5 5
  8. define LED6 6
  9. define LED7 7
  10. define LED8 8
  11.  
  12.  
  13. define LINKS_NACH_RECHT 90
  14. define RECH_NACH_LINKS 91
  15.  
  16. int direction = LINKS_NACH_RECHT;
  17.  
  18.  
  19. void setup() {
  20. pinMode()
  21.  
  22. }
  23.  
  24. boolean T1Pressed(int waitTimeInMillis) {
  25.  
  26.  
  27.  
  28. int startTime = millis();
  29. int startState = digitalRead(T1);
  30.  
  31. //button is not pressed so we return back with false
  32. if(startState == 0) {
  33. return false;
  34. }
  35.  
  36. // here we know that startState is 1
  37. // OK now we know the button is pressed (state 1). lets make sure that
  38. // it will remain pressed ( meaning it shold not change its state for at least waitTimeInMillis)
  39.  
  40. while( (millis() - startTime) < waitTimeInMillis) {
  41. if(digitalRead(T1) != startState) {
  42. return false;
  43. }
  44.  
  45. }
  46.  
  47.  
  48. return true:
  49.  
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56. void LinksNachRechtON() {
  57.  
  58. for(int pinNumber = 1 ; pinNumber <=8 ; pinNumber++ ) {
  59. digitalWrite(pinNumber, HIGH)
  60. delay(200);
  61. }
  62.  
  63. }
  64.  
  65. void RechtNachtLinksON() {
  66.  
  67. for(int pinNumber = 8 ; pinNumber <=8 ; pinNumber-- ) {
  68. digitalWrite(pinNumber, HIGH)
  69. delay(200);
  70. }
  71.  
  72. }
  73.  
  74.  
  75. void loop() {
  76.  
  77.  
  78. //short press T1Pressed(1000)
  79. if(T1Pressed(500)) {
  80. if(direction == RECH_NACH_LINKS) {
  81. direction == LINKS_NACH_RECHT;
  82. LinksNachRechtON();
  83. } else {
  84. direction == RECH_NACH_LINKS:
  85. RechtNachtLinksON();
  86. }
  87. }
  88.  
  89.  
  90. //Long press
  91. if(T1Pressed(2000)) {
  92. AllLEDsOn();
  93.  
  94. //This waits till button is still pressed
  95. while(digitalRead(T1)==HIGH) {
  96. //do nothing we are just
  97. }
  98.  
  99. //At this point we know that digitalRead(T1) is LOW meaning you lifted the finger
  100. //therefore we switch OFF all LEds
  101. AllLEDSOff();
  102.  
  103. }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement