Skip to content
Jaume Olivé Petrus edited this page Aug 28, 2017 · 12 revisions

Specification

What Comments
Identifier LINEAR_POT
Interface ADC
Provides val Potentiometer % value, from 0 to 1. 0 is 0%,
1 is 100%, 0.5 is 50%.
Properties none

Code

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("POT", adc.ADS1115, 0)

-- Read potentiometer value every 100 msecs
thread.start(function()
  while true do
    tmr.delayms(100)
    led:setfreq(1000)
    led:setduty(s:read("val"))
  end
end)
Clone this wiki locally