Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[arduino code examples for MT4v2]-05 Read free GPIO state
#1
Code:
/*
* ESP32 GPIO State Reader
* Reads the state of GPIO47, GPIO48, GPIO7, GPIO40, GPIO0, and GPIO5
* and prints the results to the serial monitor.
*
* Made by KinCony IoT: https://www.kincony.com
*/


#define GPIO_40  40
#define GPIO_48  48
#define GPIO_0   0
#define GPIO_47  47
#define GPIO_17  17



void setup() {
    Serial.begin(115200); // Initialize serial communication at 115200 baud rate
   
    // Set GPIOs as input

    pinMode(GPIO_40, INPUT);
    pinMode(GPIO_48, INPUT);
    pinMode(GPIO_0, INPUT);
    pinMode(GPIO_47, INPUT);
    pinMode(GPIO_17, INPUT);           
}

void loop() {
    // Read GPIO states
    int state_40 = digitalRead(GPIO_40);
    int state_48 = digitalRead(GPIO_48);
    int state_0  = digitalRead(GPIO_0);
    int state_47 = digitalRead(GPIO_47);
    int state_17 = digitalRead(GPIO_17);


    // Print GPIO states to the serial monitor
    Serial.printf("GPIO40: %d, GPIO48: %d, GPIO0: %d, GPIO47: %d, GPIO17: %d\n",
                  state_40, state_48, state_0, state_47, state_17);
   
    delay(1000); // Read GPIO states every second
}
arduino ino file download:

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

.zip   5-free-gpio-state.ino.merged.zip (Size: 180.12 KB / Downloads: 6)
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)