mc_workshop

DID capacitive sensor

May 16th, 2021
541
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   Capacitive sensor + LCD
  3.   July 2020 by MC Workshop.
  4.   This example code is in the public domain.
  5.   Ingresso piastra pin 9
  6.   R = 1M pin 8
  7. */
  8. #include <LiquidCrystal.h>
  9. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  10. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  11. #include <CapacitiveSensor.h>
  12. CapacitiveSensor cs_8_9 = CapacitiveSensor(8, 9);
  13. void setup()
  14. {
  15.    lcd.begin(16, 2);
  16.   cs_8_9.set_CS_AutocaL_Millis(0xFFFFFFFF);
  17.   Serial.begin(9600);
  18. }
  19. void loop()
  20. {
  21.   long start = millis();
  22.   long total =  cs_8_9.capacitiveSensor(30);
  23.   Serial.print(millis() - start);
  24.   Serial.print("\t");
  25.   Serial.println(total);
  26.   delay(300);
  27.   if (total>200){
  28.   lcd.setCursor(0, 0);
  29.   lcd.print("    Sole in      ");
  30.     lcd.setCursor(0, 1);
  31.   lcd.print(" avvicinamento ");
  32. }
  33. else
  34. {
  35.   lcd.setCursor(0, 0);
  36.   lcd.print("   Terra sana   ");
  37.   lcd.setCursor(0, 1);
  38.   lcd.print("    e vegeta    ");
  39. }
  40. }
RAW Paste Data