Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include "HX711.h"
  2. #include <LiquidCrystal.h>
  3. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  4. #define DOUT 3
  5. #define CLK 2
  6.  
  7. HX711 scale;
  8.  
  9. float calibration_factor = -46000;
  10.  
  11. void setup() {
  12. scale.begin(DOUT, CLK);
  13. scale.set_scale();
  14. scale.tare();
  15.  
  16. long zero_factor = scale.read_average();
  17.  
  18. lcd.begin(16, 2);
  19. lcd.print(" MIERNIK ");
  20. lcd.setCursor(0,1);
  21. lcd.print(" TENSOMETRYCZNY ");
  22. delay(2000);
  23. lcd.clear();
  24. }
  25.  
  26. void loop() {
  27.  
  28. scale.set_scale(calibration_factor);
  29.  
  30. float reading = scale.get_units();
  31. if (reading < 0.09)
  32. reading = 0;
  33.  
  34. lcd.setCursor(0,0);
  35. lcd.print("Sila nacisku:");
  36. int o3 = 0;
  37. float w = (reading * 9.81)*100;
  38. w = floor(w);
  39. int o1 = (int)w%10;
  40. int o2 = ((int)w%100 - o1)/10;
  41. if (w > 10000)
  42. o3 = ((int)w%100000 - o2)/100;
  43. else if (w > 1000)
  44. o3 = ((int)w%10000 - o2)/100;
  45. else
  46. o3 = ((int)w%1000 - o2)/100;
  47.  
  48. lcd.setCursor(0,1);
  49. lcd.print(" ");
  50. lcd.setCursor(0,1);
  51. lcd.print(o3);
  52. lcd.print(".");
  53. lcd.print(o2);
  54. lcd.print(o1);
  55. lcd.print(" N ");
  56.  
  57. delay(1000);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement