Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #define encoderPinA 6
  2. #define encoderPinB 7
  3. #include <LiquidCrystal.h>
  4. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  5.  
  6. int n = LOW;
  7. int encoderPinALast = LOW;
  8. int encoderPos = 0;
  9.  
  10. byte load0[8] = {
  11. B00000,
  12. B00000,
  13. B00000,
  14. B00000,
  15. B00000,
  16. B00000,
  17. B00000,
  18. B00000
  19. };
  20.  
  21. byte load1[8] = {
  22. B10000,
  23. B10000,
  24. B10000,
  25. B10000,
  26. B10000,
  27. B10000,
  28. B10000,
  29. B10000
  30. };
  31.  
  32. byte load2[8] = {
  33. B11000,
  34. B11000,
  35. B11000,
  36. B11000,
  37. B11000,
  38. B11000,
  39. B11000,
  40. B11000
  41. };
  42.  
  43. byte load3[8] = {
  44. B11100,
  45. B11100,
  46. B11100,
  47. B11100,
  48. B11100,
  49. B11100,
  50. B11100,
  51. B11100
  52. };
  53.  
  54. byte load4[8] = {
  55. B11110,
  56. B11110,
  57. B11110,
  58. B11110,
  59. B11110,
  60. B11110,
  61. B11110,
  62. B11110
  63. };
  64.  
  65. byte load5[8] = {
  66. B11111,
  67. B11111,
  68. B11111,
  69. B11111,
  70. B11111,
  71. B11111,
  72. B11111,
  73. B11111
  74. };
  75.  
  76. void setup() {
  77. // put your setup code here, to run once:
  78. Serial.begin(9600);
  79. lcd.begin(16, 2);
  80. lcd.createChar(0, load0);
  81. lcd.createChar(1, load1);
  82. lcd.createChar(2, load2);
  83. lcd.createChar(3, load3);
  84. lcd.createChar(4, load4);
  85. lcd.createChar(5, load5);
  86.  
  87. pinMode(encoderPinA, INPUT_PULLUP);
  88. pinMode(encoderPinB, INPUT_PULLUP);
  89. }
  90.  
  91. void loop() {
  92. // put your main code here, to run repeatedly:
  93. encoderStand();
  94. printPercentage();
  95. printBlokjes();
  96. double waardeTachtig = (encoderPos / 100) * 80;
  97. int volKarakter = waardeTachtig / 16;
  98.  
  99. lcd.setCursor(0, 1);
  100.  
  101. }
  102. void printBlokjes(){
  103. int temp = encoderPos;
  104. int groteGetallen = temp/5;
  105. int kleinegetallen = temp%5;
  106. for(int i = 0; i < groteGetallen; i++){
  107. lcd.write(byte(5));
  108. }
  109. lcd.write(byte(kleinegetallen));
  110. }
  111. void printPercentage(){
  112. lcd.setCursor(0, 0);
  113. if (encoderPos < 10) {
  114. lcd.print(" ");
  115. }
  116. if (encoderPos < 100) {
  117. lcd.print(" ");
  118. }
  119.  
  120. lcd.print(encoderPos);
  121. lcd.print("%");
  122. }
  123.  
  124. void encoderStand() {
  125. n = digitalRead(encoderPinA);
  126. if ((encoderPinALast == LOW) && (n == HIGH)) {
  127. if (digitalRead(encoderPinB) == LOW) {
  128. if (encoderPos >= 100) {
  129. encoderPos = 100;
  130. } else {
  131. encoderPos ++;
  132. }
  133.  
  134. } else if (!(encoderPos <= 0)) {
  135. encoderPos --;
  136. }
  137. }
  138. encoderPinALast = n;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement