Advertisement
Guest User

Kod za UV v1.0

a guest
Feb 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. int val;
  4. int encoder0PinA = 8;
  5. int encoder0PinB = 9;
  6. int encoder0Pos = 0;
  7. int encoder0PinALast = LOW;
  8. int n = LOW;
  9. int dugmePin = 10;
  10. int dugmeState = 0;
  11. int stanje = 0;
  12. const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
  13. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  14.  
  15. void setup()
  16.  
  17. // Startup poruka
  18. {
  19. pinMode(dugmePin, INPUT);
  20. lcd.begin(16, 2);
  21. pinMode (encoder0PinA, INPUT);
  22. pinMode (encoder0PinB, INPUT);
  23. lcd.print(" Welcome to ");
  24. lcd.setCursor(0,1);
  25. lcd.print(" Utepuvatch V1.0 ");
  26. delay(2000);
  27. lcd.setCursor(0,0);
  28. lcd.clear();
  29. lcd.print("Made by");
  30. lcd.setCursor(0,1);
  31. lcd.print("Aleksa and Stevan");
  32. delay(2000);
  33. lcd.clear();
  34. }
  35.  
  36.  
  37. // Glavni kod
  38.  
  39. void loop()
  40. {
  41.  
  42. dugmeState = digitalRead(dugmePin);
  43.  
  44. if (dugmeState == LOW)
  45. {
  46. stanje = 10;
  47.  
  48. }
  49.  
  50. if (stanje == 10)
  51. {
  52. lcd.setCursor(10,0);
  53. lcd.print(" ");
  54. if (encoder0Pos > 0)
  55. {
  56. encoder0Pos --;
  57. lcd.setCursor(10,0);
  58. lcd.print(encoder0Pos);
  59. delay(600);
  60. }
  61.  
  62. else
  63. {
  64. lcd.setCursor(0,1);
  65. stanje = 0;
  66. lcd.print(" Done ");
  67. delay(2000);
  68. lcd.setCursor(0,1);
  69. lcd.print("Press to start");
  70. }
  71. }
  72.  
  73.  
  74. // na dole je kod za enkoder, na gore je za posmatranje stanja dugmeta
  75.  
  76. n = digitalRead(encoder0PinA);
  77. if ((encoder0PinALast == LOW) && (n == HIGH))
  78. {
  79. if (digitalRead(encoder0PinB) == LOW)
  80.  
  81. {
  82. encoder0Pos--;
  83. if (encoder0Pos <0)
  84. {
  85. encoder0Pos = 0;
  86. }
  87. }
  88.  
  89. else
  90.  
  91. {
  92. encoder0Pos++;
  93. }
  94.  
  95. lcd.setCursor(0,0);
  96. lcd.print("UV timer: ");
  97. lcd.print(" ");
  98. lcd.setCursor(10,0);
  99. lcd.print (encoder0Pos);
  100. lcd.setCursor(14,0);
  101. lcd.print("min");
  102. lcd.setCursor(0,1);
  103. lcd.print("Press to start");
  104.  
  105. }
  106. encoder0PinALast = n;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement