Advertisement
mikroavr

wdt_external_pcf

Mar 26th, 2024
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "PCF8574.h"
  2. PCF8574 pcf8574(0x20);
  3. byte pinWDT = P7;
  4. byte pinLED = P4;
  5.  
  6. byte pinRel[] = {P0, P1, P2, P3};
  7.  
  8. bool stateWDT = 0;
  9. byte dry[] = {35, 34, 39, 36};
  10. unsigned cur_time_wdt, old_time_wdt;
  11.  
  12.  
  13. void setup() {
  14.   // put your setup code here, to run once:
  15.   Serial.begin(115200);
  16.  
  17.   Serial.println("init pcf: ");
  18.  
  19.   for (int i = 0; i < sizeof(pinRel); i++) {
  20.     Serial.print(pinRel[i]);
  21.     pinMode(pinRel[i], OUTPUT);
  22.   }
  23.  
  24.   pcf8574.pinMode(pinWDT, OUTPUT);
  25.   pcf8574.pinMode(pinLED, OUTPUT);
  26.  
  27.   if (pcf8574.begin()) {
  28.     Serial.println("OK");
  29.   } else {
  30.     Serial.println("KO");
  31.   }
  32.   delay(100);
  33.   for (int i = 0; i < sizeof(pinRel); i++) {
  34.     pcf8574.digitalWrite(pinRel[i], HIGH); // SET RELAY OFF
  35.   }
  36. }
  37.  
  38. void loop() {
  39.   // put your main code here, to run repeatedly:
  40.   cur_time_wdt = millis();
  41.   if (cur_time_wdt - old_time_wdt >= 500) {
  42.     seed_wdt();
  43.     for (int i = 0; i < sizeof(dry); i++) {
  44.       Serial.print(digitalRead(dry[i]));
  45.       Serial.print(",");
  46.     }
  47.     Serial.println();
  48.     old_time_wdt = millis();
  49.   }
  50. }
  51.  
  52. void seed_wdt() {
  53.   stateWDT = !stateWDT;
  54.   pcf8574.digitalWrite(P7, stateWDT);
  55.   pcf8574.digitalWrite(P4, stateWDT);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement