Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[arduino code examples for MT4]-03 Read free GPIO state
#1
Code:
/*
  Made by KinCony IoT: https://www.kincony.com

  Monitor GPIO0, GPIO18, GPIO8
  Print to Serial when state changes
*/

#define PIN_0   0
#define PIN_18  18
#define PIN_8   8

int lastState0;
int lastState18;
int lastState8;

void setup() {
  Serial.begin(115200);

  pinMode(PIN_0, INPUT_PULLUP);
  pinMode(PIN_18, INPUT_PULLUP);
  pinMode(PIN_8, INPUT_PULLUP);

  lastState0  = digitalRead(PIN_0);
  lastState18 = digitalRead(PIN_18);
  lastState8  = digitalRead(PIN_8);

  Serial.println("GPIO Monitor Started");
}

void loop() {

  int state0 = digitalRead(PIN_0);
  if (state0 != lastState0) {
    Serial.print("GPIO0 changed to: ");
    Serial.println(state0);
    lastState0 = state0;
  }

  int state18 = digitalRead(PIN_18);
  if (state18 != lastState18) {
    Serial.print("GPIO18 changed to: ");
    Serial.println(state18);
    lastState18 = state18;
  }

  int state8 = digitalRead(PIN_8);
  if (state8 != lastState8) {
    Serial.print("GPIO8 changed to: ");
    Serial.println(state8);
    lastState8 = state8;
  }

  delay(10);
}
arduino ino file download: 

.zip   Free-GPIO.zip (Size: 539 bytes / Downloads: 8)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   Free-GPIO.ino.merged.zip (Size: 180.26 KB / Downloads: 16)
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)