forked from whitecatboard/Lua-RTOS-ESP32
-
Notifications
You must be signed in to change notification settings - Fork 0
LINEAR POT SENSOR
Thomas E. Horner edited this page Mar 12, 2019
·
12 revisions
What | Comments | |
---|---|---|
Identifier | LINEAR_POT | |
Interface | ADC | |
Provides | val | Potentiometer % value, from 0.0 to 1. 0 is 0%, 1.0 is 100%, 0.5 is 50%. |
Properties | none | |
Callbacks? | no |
In this example a potentiometer is used to control the brightness of a led (using PWM).
-- Attach a led at GPIO32
led = pwm.attach(pio.GPIO32, 1000, 0)
led:start()
-- Attach a potentiometer connected to an external ADC (ADS1115) / cannel 0
s = sensor.attach("LINEAR_POT", adc.ADS1115, 0)
-- Read potentiometer value every 10 msecs
thread.start(function()
while true do
tmr.delayms(10)
led:setfreq(1000)
led:setduty(s:read("val"))
end
end)