Advertisement
computermuseo

tester emf arduino

Jun 13th, 2015
1,693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  3. const int backlight = 10;
  4. #define sample 300
  5. int inPin = 5;
  6. float val;
  7. int pin11 = 13;
  8. int array1[sample];
  9. unsigned long averaging;
  10.  
  11. void setup() {
  12. pinMode(backlight, OUTPUT);
  13. digitalWrite(backlight, HIGH);
  14. lcd.begin(16,2);
  15. lcd.print("EMF Tester");
  16. lcd.setCursor(0,1); //Va alla riga 1
  17. }
  18.  
  19. void loop() {
  20. for(int i = 0; i < sample; i++){
  21. array1[i] = analogRead(inPin);
  22. averaging += array1[i];
  23. }
  24.  
  25. val = averaging / sample;
  26. val = constrain(val, 0, 100);
  27. val = map(val, 0, 100, 0, 255);
  28. analogWrite(pin11, val);
  29. averaging = 0;
  30. lcd.setCursor(0,1);
  31. lcd.print(val);
  32. lcd.print(" ");
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement