-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDimmer.py
More file actions
35 lines (27 loc) · 865 Bytes
/
Dimmer.py
File metadata and controls
35 lines (27 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Dimmer
Demonstrates sending data from the computer to the ESP32 board, in this case
to control the brightness of an LED. The data is sent in individual bytes.
ESP32 reads these bytes and uses them to set the brightness of the LED.
The circuit:
- LED attached from GPIO27 to ground.
- Serial connection to Processing, Max/MSP, or another serial application
"""
from machine import Pin, PWM
from time import sleep
frequency = 5000
led = PWM(Pin(27), frequency)
def inputNumber(message):
while True:
try:
userInput = int(input(message))
except ValueError:
print("Not an integer! Try again.")
continue
else:
return userInput
break
while True:
brightness = inputNumber("Enter brightness: ")
led.duty(brightness)
sleep(0.005)