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

  This program reads the digital state of GPIO15 and GPIO16 on an ESP32
  and prints their state (HIGH or LOW) to the serial monitor every 500ms.
*/

#define PIN_GPIO15 15  // Define GPIO15
#define PIN_GPIO16 16  // Define GPIO16

void setup() {
  Serial.begin(115200);               // Initialize serial communication at 115200 baud
  pinMode(PIN_GPIO15, INPUT);         // Set GPIO15 as input
  pinMode(PIN_GPIO16, INPUT);         // Set GPIO16 as input
  Serial.println("ESP32 GPIO15 and GPIO16 State Monitor");
}

void loop() {
  int state15 = digitalRead(PIN_GPIO15);  // Read state of GPIO15
  int state16 = digitalRead(PIN_GPIO16);  // Read state of GPIO16

  // Print the state to the serial monitor
  Serial.print("GPIO15: ");
  Serial.print(state15 == HIGH ? "HIGH" : "LOW");
  Serial.print("  |  GPIO16: ");
  Serial.println(state16 == HIGH ? "HIGH" : "LOW");

  delay(500);  // Wait for 500 milliseconds before reading again
}
arduino ino file download:

.zip   1-free-gpio-state.zip (Size: 632 bytes / Downloads: 230)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   1-free-gpio-state.ino.merged.zip (Size: 181.39 KB / Downloads: 238)
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)