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

   Demo: KinCony B2 Digital Input Read
   Board: KinCony B2 (ESP32)

   Digital Input 1 -> GPIO6
   Digital Input 2 -> GPIO7
*/

#define DI1_PIN 6
#define DI2_PIN 7

// Store previous input states
int lastDI1State = HIGH;
int lastDI2State = HIGH;

void setup()
{
  // Initialize serial monitor
  Serial.begin(115200);
  Serial.println("KinCony B2 Digital Input Demo");

  // Configure digital input pins
  // Change INPUT to INPUT_PULLUP if your hardware requires internal pull-up
  pinMode(DI1_PIN, INPUT_PULLUP);
  pinMode(DI2_PIN, INPUT_PULLUP);

  // Read initial states
  lastDI1State = digitalRead(DI1_PIN);
  lastDI2State = digitalRead(DI2_PIN);

  Serial.print("DI1 Initial State: ");
  Serial.println(lastDI1State);

  Serial.print("DI2 Initial State: ");
  Serial.println(lastDI2State);
}

void loop()
{
  // Read current input states
  int di1State = digitalRead(DI1_PIN);
  int di2State = digitalRead(DI2_PIN);

  // Check if DI1 state changed
  if (di1State != lastDI1State)
  {
    lastDI1State = di1State;

    Serial.print("DI1 Changed: ");
    Serial.println(di1State);
  }

  // Check if DI2 state changed
  if (di2State != lastDI2State)
  {
    lastDI2State = di2State;

    Serial.print("DI2 Changed: ");
    Serial.println(di2State);
  }

  // Small delay for stability
  delay(10);
}
arduino ino file download:

.zip   2-digital-input.zip (Size: 697 bytes / Downloads: 7)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 

.zip   2-digital-input.ino.merged.zip (Size: 180.26 KB / Downloads: 11)
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)