claudiusmarius

ESP32_Hallsensor01

Jul 15th, 2020
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int led = 2;
  2.   bool etatLed = 0;
  3.   int val = 0;
  4.  
  5.   void setup()
  6.   {
  7.   Serial.begin(115200);
  8.   pinMode(led, OUTPUT);
  9.   digitalWrite(led, LOW);  
  10.   }
  11.  
  12. void loop() {
  13.  
  14.  
  15.   val = 0;
  16.   for (int i = 0; i<500; i++)
  17.   {
  18.     val += hallRead();
  19.     delay(1);
  20.   }
  21.    val /=500;
  22.  
  23.  if (val < 12)
  24.  {
  25.   digitalWrite(led, HIGH);
  26.  }
  27.  else
  28.  {
  29.   digitalWrite(led, LOW);
  30.  }
  31.   Serial.println(val);
  32.   delay(20);
  33. }
RAW Paste Data