SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
(continued from previous page)
while
True
:
value
=
potentiometer
.
read_u16()
(value)
led
.
duty_u16(value)
utime
.
sleep_ms(
200
)
What more?
Let’s use the potentiometer to swing the servo from left to right!
import
machine
import
utime
potentiometer
=
machine
.
ADC(
28
)
servo
=
machine
.
PWM(machine
.
Pin(
15
))
servo
.
freq(
50
)
def
interval_mapping
(x, in_min, in_max, out_min, out_max):
return
(x
-
in_min)
*
(out_max
-
out_min)
/
(in_max
-
in_min)
+
out_min
def
servo_write
(pin,angle):
pulse_width
=
interval_mapping(angle,
0
,
180
,
0.5
,
2.5
)
duty
=
int
(interval_mapping(pulse_width,
0
,
20
,
0
,
65535
))
pin
.
duty_u16(duty)
while
True
:
value
=
potentiometer
.
read_u16()
angle
=
interval_mapping(value,
0
,
65535
,
0
,
180
)
servo_write(servo,angle)
utime
.
sleep_ms(
200
)
90
Chapter 3. For MicroPython User
Summary of Contents for Thales Kit
Page 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Page 2: ......
Page 4: ...ii ...
Page 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Page 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Page 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...