Advertisement
rs3hc

ESP Bat

Jan 2nd, 2022
2,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "esp_adc_cal.h"
  2. #include <Arduino.h>
  3. int BatIntValue = 0;        // value read from the
  4. int TestIntValue = 0;        // value read from the
  5. int Count = 0;
  6. unsigned long lastTimeCycle = 0;
  7. unsigned long lastTimeDelay = 1000;
  8.  
  9. void setup()
  10. {
  11.   Serial.begin(115200);
  12. }
  13.  
  14. void loop()
  15. {
  16.   if ((millis() - lastTimeCycle) > lastTimeDelay) {
  17.     Count++;
  18.     BatIntValue = analogRead(35);
  19.     TestIntValue = analogRead(32);
  20.     Serial.print("ID: ");
  21.     Serial.print(Count);
  22.     Serial.print(" > BAT INT: ");
  23.     Serial.print(BatIntValue);
  24.     Serial.print(" | BAT Berechnet: ");
  25.     Serial.print((BatIntValue * 3.3 / 4095 * 2);   // 2x wegen Spannungsteiler
  26.     //Serial.print(BatIntValue * 3.3 / 4095 * 2);   // 2x wegen Spannungsteiler
  27.     Serial.print("V | Test INT: ");
  28.     Serial.print(TestIntValue);
  29.     Serial.print(" | Test Berechnet: ");
  30.     Serial.print(TestIntValue * 3.3 / 4095);
  31.     Serial.println(" V");
  32.     lastTimeCycle = millis();
  33.     }
  34. }
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement