keyPressedPin1.ino 660 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. KeyPressed on PIN1
  3. by Mischianti Renzo <http://www.mischianti.org>
  4. https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/
  5. */
  6. #include "Arduino.h"
  7. #include "PCF8574.h"
  8. // Set i2c address
  9. PCF8574 pcf8574(0x39);
  10. unsigned long timeElapsed;
  11. void setup()
  12. {
  13. Serial.begin(115200);
  14. delay(1000);
  15. pcf8574.pinMode(P0, OUTPUT);
  16. pcf8574.pinMode(P1, INPUT);
  17. Serial.print("Init pcf8574...");
  18. if (pcf8574.begin()){
  19. Serial.println("OK");
  20. }else{
  21. Serial.println("KO");
  22. }
  23. }
  24. void loop()
  25. {
  26. uint8_t val = pcf8574.digitalRead(P1);
  27. if (val==HIGH) Serial.println("KEY PRESSED");
  28. delay(50);
  29. }