Advertisement
mikroavr

remap_tca_pin

Jan 14th, 2024
1,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Wire.h"
  2. #include "TCA9555.h"
  3. TCA9555 TCA1(0x20);
  4. TCA9555 TCA2(0x21);
  5.  
  6. unsigned long cur_time, old_time;
  7. int ledState = LOW;
  8.  
  9. byte pin_tca1[] = {0, 1, 2, 3, 4, 5, 6, 7, 13, 12, 11, 10};
  10. byte pin_tca2[] = {7, 6, 5, 4, 3, 2, 1, 0, 10, 11, 12, 13};
  11.  
  12. byte pin_led = 16;
  13. byte dt_tca1[20];
  14. byte dt_tca2[20];
  15.  
  16. void setup() {
  17.   // put your setup code here, to run once:
  18.   delay(10);
  19.   Serial.begin(115200);
  20.   Serial.println();
  21.   delay(100);
  22.   pinMode(pin_led, OUTPUT);
  23.  
  24.   Wire.begin();
  25.   TCA1.begin();
  26.   TCA2.begin();
  27.  
  28.   for (int i = 0; i < sizeof(pin_tca1); i++) {
  29.     Serial.print(i); Serial.print(",");
  30.     TCA1.pinMode(pin_tca1[i], INPUT_PULLUP);
  31.     TCA2.pinMode(pin_tca2[i], INPUT_PULLUP);
  32.   }
  33.   Serial.println();
  34. }
  35.  
  36. void loop() {
  37.   // put your main code here, to run repeatedly:
  38.   cur_time = millis();
  39.   if (cur_time - old_time >= 100) {
  40.     ledState = !ledState;
  41.     digitalWrite(pin_led, ledState);
  42.     Serial.print("TCA1: ");
  43.     for (int i = 0; i < sizeof(pin_tca1); i++) {
  44.       dt_tca1[i] = TCA1.digitalRead(pin_tca1[i]);
  45.       Serial.print(dt_tca1[i]);
  46.       Serial.print(",");
  47.       delay(5);
  48.     }
  49.     Serial.println();
  50.  
  51.     Serial.print("TCA2: ");
  52.     for (int i = 0; i < sizeof(pin_tca2); i++) {
  53.       dt_tca2[i] = TCA2.digitalRead(pin_tca2[i]);
  54.       Serial.print(dt_tca2[i]);
  55.       Serial.print(",");
  56.       delay(5);
  57.     }
  58.     Serial.println();
  59.     old_time = millis();
  60.   }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement