Advertisement
Guest User

Untitled

a guest
Nov 13th, 2020
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. #include "HX711.h"
  2. #include <TM1638plus.h>
  3. char odczyt[100];
  4. float ciezar;
  5. HX711 waga;
  6. #define STROBE_TM 4
  7. #define CLOCK_TM 6
  8. #define DIO_TM 7
  9. bool high_freq = false; //default false, If using a high freq CPU > ~100 MHZ set to true.
  10. //Constructor object (GPIO STB , GPIO CLOCK , GPIO DIO, use high freq MCU)
  11. TM1638plus tm(STROBE_TM, CLOCK_TM , DIO_TM, high_freq);
  12. int ust=100;
  13. int otwPin = 3;
  14. int ustPin = A1;
  15. int prze = 10;
  16.  
  17.  
  18.  
  19.  
  20. float calibration_factor = 53270;
  21. uint8_t buttons = tm.readButtons();
  22.  
  23.  
  24. void setup() {
  25. Serial.begin(9600);
  26. pinMode(otwPin, INPUT_PULLUP);
  27. waga.begin(8, 9);
  28. waga.set_scale();
  29. waga.tare();
  30. waga.power_up();
  31. tm.displayBegin();
  32. pinMode(prze, OUTPUT);
  33. pinMode(ustPin, INPUT);
  34.  
  35. }
  36.  
  37. void loop() {
  38. uint8_t buttons = tm.readButtons();
  39.  
  40.  
  41. waga.set_scale(calibration_factor);
  42. ciezar=waga.get_units();
  43. dtostrf(ciezar,7,2,odczyt);
  44.  
  45. if(buttons == 1)
  46. {
  47. ust = map(analogRead(ustPin), 0, 1000, 1400, 1600);
  48. if((analogRead(ustPin) >= 0) && ((analogRead(ustPin) < 50)))
  49. {
  50. tm.reset();
  51. tm.displayText(" 14.00");
  52. delay(100);
  53. }
  54. else if((analogRead(ustPin) >= 50) && ((analogRead(ustPin) < 100)))
  55. {
  56. tm.reset();
  57. tm.displayText(" 14.10");
  58. delay(100);
  59. }
  60. else if((analogRead(ustPin) >= 100) && ((analogRead(ustPin) < 150)))
  61. {
  62. tm.reset();
  63. tm.displayText(" 14.20");
  64. delay(100);
  65. }
  66. else if((analogRead(ustPin) >= 150) && ((analogRead(ustPin) < 200)))
  67. {
  68. tm.reset();
  69. tm.displayText(" 14.30");
  70. delay(100);
  71. }
  72. else if((analogRead(ustPin) >= 200) && ((analogRead(ustPin) < 250)))
  73. {
  74. tm.reset();
  75. tm.displayText(" 14.40");
  76. delay(100);
  77. }
  78. else if((analogRead(ustPin) >= 250) && ((analogRead(ustPin) < 300)))
  79. {
  80. tm.reset();
  81. tm.displayText(" 14.50");
  82. delay(100);
  83. }
  84. else if((analogRead(ustPin) >= 300) && ((analogRead(ustPin) < 350)))
  85. {
  86. tm.reset();
  87. tm.displayText(" 14.60");
  88. delay(100);
  89. }
  90. else if((analogRead(ustPin) >= 350) && ((analogRead(ustPin) < 400)))
  91. {
  92. tm.reset();
  93. tm.displayText(" 14.70");
  94. delay(100);
  95. }
  96. else if((analogRead(ustPin) >= 400) && ((analogRead(ustPin) < 450)))
  97. {
  98. tm.reset();
  99. tm.displayText(" 14.80");
  100. delay(100);
  101. }
  102. else if((analogRead(ustPin) >= 450) && ((analogRead(ustPin) < 500)))
  103. {
  104. tm.reset();
  105. tm.displayText(" 14.90");
  106. delay(100);
  107. }
  108. else if((analogRead(ustPin) >= 500) && ((analogRead(ustPin) < 550)))
  109. {
  110. tm.reset();
  111. tm.displayText(" 15.00");
  112. delay(100);
  113. }
  114. else if((analogRead(ustPin) >= 550) && ((analogRead(ustPin) < 600)))
  115. {
  116. tm.reset();
  117. tm.displayText(" 15.10");
  118. delay(100);
  119. }
  120. else if((analogRead(ustPin) >= 600) && ((analogRead(ustPin) < 650)))
  121. {
  122. tm.reset();
  123. tm.displayText(" 15.20");
  124. delay(100);
  125. }
  126. else if((analogRead(ustPin) >= 650) && ((analogRead(ustPin) < 700)))
  127. {
  128. tm.reset();
  129. tm.displayText(" 15.30");
  130. delay(100);
  131. }
  132. else if((analogRead(ustPin) >= 700) && ((analogRead(ustPin) < 750)))
  133. {
  134. tm.reset();
  135. tm.displayText(" 15.40");
  136. delay(100);
  137. }
  138. else if((analogRead(ustPin) >= 750) && ((analogRead(ustPin) < 800)))
  139. {
  140. tm.reset();
  141. tm.displayText(" 15.50");
  142. delay(100);
  143. }
  144. else if((analogRead(ustPin) >= 800) && ((analogRead(ustPin) < 850)))
  145. {
  146. tm.reset();
  147. tm.displayText(" 15.60");
  148. delay(100);
  149. }
  150. else if((analogRead(ustPin) >= 850) && ((analogRead(ustPin) < 900)))
  151. {
  152. tm.reset();
  153. tm.displayText(" 15.70");
  154. delay(100);
  155. }
  156. else if((analogRead(ustPin) >= 900) && ((analogRead(ustPin) < 950)))
  157. {
  158. tm.reset();
  159. tm.displayText(" 15.80");
  160. delay(100);
  161. }
  162. else if((analogRead(ustPin) >= 950) && ((analogRead(ustPin) < 1000)))
  163. {
  164. tm.reset();
  165. tm.displayText(" 15.90");
  166. delay(100);
  167. }
  168. else if(analogRead(ustPin) >= 1000)
  169. {
  170. tm.reset();
  171. tm.displayText(" 16.00");
  172. delay(100);
  173. }
  174. }
  175.  
  176. else if(digitalRead(otwPin)==LOW)
  177. {
  178. tm.reset();
  179. tm.displayText("OTwArTE");
  180. Serial.println("otwarte");
  181. digitalWrite(prze, LOW);
  182. delay(5000);
  183. }
  184.  
  185. else
  186. {
  187. if(ciezar <= ust*0.01)
  188. {
  189. digitalWrite(prze, HIGH);
  190. }
  191. else if(ciezar > ust*0.01)
  192. {
  193. digitalWrite(prze, LOW);
  194. delay(1000);
  195. }
  196. tm.displayText(odczyt);
  197. Serial.println(odczyt);
  198. Serial.println(ust);
  199. delay(100);
  200. }
  201.  
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement