Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "EEPROM.h"
- #include "Wire.h"
- #include "TCA9555.h"
- TCA9555 TCA1(0x20);
- TCA9555 TCA2(0x21);
- unsigned long cur_time, old_time;
- int ledState = LOW;
- byte pin_tca[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
- byte pin_led = 16;
- byte dt_tca1[20];
- byte dt_tca2[20];
- byte addr_status = 2;
- int dt_status = 0;
- void setup() {
- // put your setup code here, to run once:
- delay(10);
- Serial.begin(115200);
- Serial.println();
- if (!EEPROM.begin(1000)) {
- Serial.println("Failed to initialise EEPROM");
- Serial.println("Restarting...");
- delay(1000);
- ESP.restart();
- }
- delay(100);
- dt_status = EEPROM.readInt(addr_status);
- if(dt_status == -1 )dt_status = 0;
- Serial.print("dt_status: ");
- Serial.println(dt_status);
- delay(2000);
- pinMode(pin_led, OUTPUT);
- Wire.begin();
- TCA1.begin();
- TCA2.begin();
- for (int i = 0; i < sizeof(pin_tca); i++) {
- Serial.print(i); Serial.print(",");
- TCA1.pinMode(pin_tca[i], INPUT_PULLUP);
- TCA2.pinMode(pin_tca[i], INPUT_PULLUP);
- }
- Serial.println();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- cur_time = millis();
- if (cur_time - old_time >= 100) {
- ledState = !ledState;
- digitalWrite(pin_led, ledState);
- Serial.print("TCA1: ");
- for (int i = 0; i < sizeof(pin_tca) - 4; i++) {
- dt_tca1[i] = TCA1.digitalRead(pin_tca[i]);
- Serial.print(dt_tca1[i]);
- Serial.print(",");
- if(dt_tca1[i] == 0){
- dt_status ++;
- EEPROM.writeInt(addr_status, dt_status);
- EEPROM.commit();
- }
- delay(20);
- }
- Serial.println();
- Serial.print("TCA2: ");
- for (int i = 0; i < sizeof(pin_tca) - 4; i++) {
- dt_tca2[i] = TCA2.digitalRead(pin_tca[i]);
- Serial.print(dt_tca2[i]);
- Serial.print(",");
- if(dt_tca2[i] == 0){
- dt_status ++;
- EEPROM.writeInt(addr_status, dt_status);
- EEPROM.commit();
- }
- delay(20);
- }
- Serial.println();
- Serial.print("dt_status: ");
- Serial.println(dt_status);
- old_time = millis();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement