View Categories

Sample projects involving GPIO and touch pins with coding

2 min read

Here are a couple of sample projects involving GPIO and touch pins for your LionBit development board. I’ll provide a brief description of each project and include example code snippets to get you started. These projects demonstrate how to use these pins for different applications.

Project 1: Digital Door Lock with Touch Pins

Description: Create a simple digital door lock system using touch pins. When a specific touch sequence is detected, the door lock will either lock or unlock.

Components Needed:

  • LionBit Development Board
  • Touch Sensor Module
  • Servo Motor
  • A door or simulated locking mechanism

Code:

#include <LionBit.h>

int touchPin1 = GPIO0;  // Define the touch pins
int touchPin2 = GPIO2;

Servo doorLock;  // Create a servo object

void setup() {
  LionBit.begin();
  doorLock.attach(GPIO5);  // Attach the servo to a GPIO pin
}

void loop() {
  if (LionBit.isTouchDetected(touchPin1) && LionBit.isTouchDetected(touchPin2)) {
    // If both touch pins are touched, unlock the door
    doorLock.write(0);  // Rotate the servo to unlock position
    delay(2000);  // Allow time for the door to open
    doorLock.write(90);  // Rotate the servo to lock position
  }
}

Project 2: LED Traffic Light with GPIO Pins

Description: Create a simple traffic light simulation using LED components and GPIO pins. The traffic light will cycle through the red, yellow, and green lights in a loop.

Components Needed:

  • LionBit Development Board
  • 3 LEDs (red, yellow, green)
  • Appropriate current-limiting resistors
  • Breadboard and jumper wires

Code:

#include <LionBit.h>

int redLED = GPIO0;
int yellowLED = GPIO2;
int greenLED = GPIO4;

void setup() {
  LionBit.begin();
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
}

void loop() {
  digitalWrite(redLED, HIGH);    // Red
  digitalWrite(yellowLED, LOW);
  digitalWrite(greenLED, LOW);
  delay(3000);

  digitalWrite(redLED, LOW);     // Green
  digitalWrite(yellowLED, LOW);
  digitalWrite(greenLED, HIGH);
  delay(3000);

  digitalWrite(redLED, LOW);     // Yellow
  digitalWrite(yellowLED, HIGH);
  digitalWrite(greenLED, LOW);
  delay(1000);
}

These sample projects showcase how to use GPIO pins and touch pins in practical applications. You can modify and expand upon these projects to suit your specific needs or create entirely new projects that leverage these pins for various interactive and functional purposes.