ledWemos.ino 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * PCF8574 GPIO Port Expand
  3. * http://nopnop2002.webcrow.jp/WeMos/WeMos-25.html
  4. *
  5. * PCF8574 ----- WeMos
  6. * A0 ----- GRD
  7. * A1 ----- GRD
  8. * A2 ----- GRD
  9. * VSS ----- GRD
  10. * VDD ----- 5V/3.3V
  11. * SDA ----- GPIO_4(PullUp)
  12. * SCL ----- GPIO_5(PullUp)
  13. *
  14. * P0 ----------------- LED0
  15. * P1 ----------------- LED1
  16. * P2 ----------------- LED2
  17. * P3 ----------------- LED3
  18. * P4 ----------------- LED4
  19. * P5 ----------------- LED5
  20. * P6 ----------------- LED6
  21. * P7 ----------------- LED7
  22. *
  23. */
  24. #include "Arduino.h"
  25. #include "PCF8574.h" // https://github.com/xreef/PCF8574_library
  26. // Set i2c address
  27. PCF8574 pcf8574(0x20);
  28. void setup()
  29. {
  30. Serial.begin(9600);
  31. delay(1000);
  32. // Set pinMode to OUTPUT
  33. for(int i=0;i<8;i++) {
  34. pcf8574.pinMode(i, OUTPUT);
  35. }
  36. Serial.print("Init pcf8574...");
  37. if (pcf8574.begin()){
  38. Serial.println("OK");
  39. }else{
  40. Serial.println("KO");
  41. }
  42. }
  43. void loop()
  44. {
  45. static int pin = 0;
  46. pcf8574.digitalWrite(pin, HIGH);
  47. delay(1000);
  48. pcf8574.digitalWrite(pin, LOW);
  49. delay(1000);
  50. pin++;
  51. if (pin > 7) pin = 0;
  52. }