Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions 07.LED_TOUCH_CONTROL/led_touch_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Code to control LED by capacitive touch on the ESP32 board.

import machine
from machine import TouchPad,Pin

# The 4 pin LED pins are connected to GPIO pins numbered 15,4 and 2 in the following way:
red = machine.Pin(15, machine.Pin.OUT)
blue = machine.Pin(4, machine.Pin.OUT)
green = machine.Pin(2, machine.Pin.OUT)

on_pad = TouchPad(Pin(14)) # This will signal the touch for turning the LED on.
off_pad = TouchPad(Pin(12)) # This will signal the touch for turning the LED off.

while True:
x = on_pad.read() # Read the sensor values and wait for a touch.
y = off_pad.read()
if (x<100): # When the ON sensor is touched, turn on the LED.
green.on() # We are using the Green colored LED as an example, any of the LED colors may be used.
if (y<100): # When the OFF sensor is touched, turn off the LED.
green.off()

15 changes: 15 additions & 0 deletions 07.LED_TOUCH_CONTROL/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 07.ACCESS_POINT
## NOTE:
This program will run only on the *ESP32* board, as it is using the capacitive touch functionality.

To run the program use the following ampy command

## MAC OS
```bash
ampy --port /dev/tty.SLAB_USBtoUART run led_touch_control.py
```

## Linux
```bash
ampy --port /dev/ttyUSB0 run led_touch_control.py
```