mpmcws

Sensore di livello

Jun 15th, 2018
35
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* MPMC workshop aprile 2018
  2.   This example code is in the public domain. */
  3.  
  4. int nRainIn = A0;
  5. int nRainDigitalIn = 2;
  6. int nRainVal;
  7. boolean bIsRaining = false;
  8. String strRaining;
  9. void setup() {
  10.   Serial.begin(9600);
  11.   pinMode(2, INPUT);
  12.   pinMode (9, OUTPUT);
  13. }
  14. void loop() {
  15.   nRainVal = analogRead(nRainIn);
  16.   bIsRaining = !(digitalRead(nRainDigitalIn));
  17.   if (bIsRaining) {
  18.     strRaining = "ALLARM";
  19.     digitalWrite(9, HIGH);
  20.   }
  21.   else {
  22.     strRaining = "OK";
  23.     digitalWrite(9, LOW);
  24.   }
  25.   Serial.print("Status: ");
  26.   Serial.print(strRaining);
  27.   Serial.print("\t Level: ");
  28.   Serial.println(nRainVal);
  29.   delay(3000);
  30. }
RAW Paste Data