Advertisement
Rehys

Untitled

Nov 21st, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #define CLK 52
  4. #define DT 50
  5. #define SW 48
  6.  
  7. LiquidCrystal_I2C lcd(0x27,20,4);
  8.  
  9. int counter = 0;
  10. int state;
  11. int lastState;
  12. int volba;
  13.  
  14. void setup()
  15. {
  16. Serial.begin(9600);
  17. lcd.init();
  18. lcd.backlight();
  19. Serial.begin(9600);
  20.  
  21. pinMode(CLK,INPUT);
  22. pinMode(DT,INPUT);
  23. pinMode(SW,INPUT);
  24. Serial.begin(9600);
  25.  
  26. lastState = digitalRead(CLK);
  27. }
  28.  
  29. void loop() {
  30. state = digitalRead(CLK);
  31. if(state != lastState)
  32. {
  33. if(digitalRead(DT) != state)
  34. {
  35. counter++;
  36. }
  37. else
  38. {
  39. counter--;
  40. }
  41. lcd.clear();
  42. lcd.setCursor(0,1);
  43. lcd.print("Pozice: ");
  44. lcd.print(counter);
  45. Serial.print(counter);
  46. Serial.println();
  47. if(counter<0){
  48. counter=5;}
  49. if(counter>=6){
  50. counter=0;}
  51. if(counter==0 or counter==1){
  52. lcd.clear();
  53. lcd.setCursor(2,0);
  54. lcd.print("Zvolte napoj");
  55. lcd.setCursor(5,1);
  56. lcd.print("Jahoda");}
  57. if(counter==2 or counter==3){
  58. lcd.clear();
  59. lcd.setCursor(2,0);
  60. lcd.print("Zvolte napoj");
  61. lcd.setCursor(5,1);
  62. lcd.print("Malina");}
  63. if(counter==4 or counter==5){
  64. lcd.clear();
  65. lcd.setCursor(2,0);
  66. lcd.print("Zvolte napoj");
  67. lcd.setCursor(4,1);
  68. lcd.print("Boruvka");}
  69.  
  70. }
  71.  
  72. if(digitalRead(SW) != 1)
  73. {
  74. volba++;
  75. counter=0;
  76. }
  77.  
  78. lastState= state;
  79.  
  80. }
  81.  
  82. if(volba==1 and counter==0 or volba==1 and counter==1)
  83. {
  84. lcd.clear();
  85. lcd.setCursor(4,0)
  86. lcd.print("Zvolte silu");
  87. lcd.setCursor(1,5)
  88. lcd.print("-");
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement