Advertisement
mikroavr

input_pcf_analog_isolate

Mar 14th, 2024 (edited)
596
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 IN1 = P3;
  4. byte IN2 = P2;
  5. byte IN3 = P1;
  6. byte IN4 = P0;
  7. byte LED = 15;
  8. bool stateLed = 0;
  9. unsigned long cur_time, old_time;
  10. void setup() {
  11.   // put your setup code here, to run once:
  12.   delay(100);
  13.   Serial.begin(115200);
  14.   pinMode(LED, OUTPUT);
  15.   pcf8574.pinMode(IN1, INPUT);
  16.   pcf8574.pinMode(IN2, INPUT);
  17.   pcf8574.pinMode(IN3, INPUT);
  18.   pcf8574.pinMode(IN4, INPUT);
  19.   Serial.print("Init pcf8574...");
  20.   if (pcf8574.begin()) {
  21.     Serial.println("OK");
  22.   } else {
  23.     Serial.println("KO");
  24.   }
  25.   delay(100);
  26. }
  27.  
  28. void loop() {
  29.   // put your main code here, to run repeatedly:
  30.   cur_time = millis();
  31.   if(cur_time - old_time >= 3000){
  32.     stateLed = !stateLed;
  33.     digitalWrite(LED,stateLed);
  34.     Serial.print(pcf8574.digitalRead(IN1));
  35.     Serial.print(pcf8574.digitalRead(IN2));
  36.     Serial.print(pcf8574.digitalRead(IN3));
  37.     Serial.println(pcf8574.digitalRead(IN4));
  38.     old_time = millis();
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement