SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
Code
Here, we can choose our favorite color in drawing software (such as paint) and display it with RGB LED.
import
machine
import
utime
red
=
machine
.
PWM(machine
.
Pin(
13
))
green
=
machine
.
PWM(machine
.
Pin(
14
))
blue
=
machine
.
PWM(machine
.
Pin(
15
))
red
.
freq(
1000
)
green
.
freq(
1000
)
blue
.
freq(
1000
)
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
color_to_duty
(rgb_value):
rgb_value
=
int
(interval_mapping(rgb_value,
0
,
255
,
0
,
65535
))
return
rgb_value
def
color_set
(red_value,green_value,blue_value):
red
.
duty_u16(color_to_duty(red_value))
green
.
duty_u16(color_to_duty(green_value))
blue
.
duty_u16(color_to_duty(blue_value))
color_set(
255
,
128
,
0
)
Write the RGB value into color_set(), you will be able to see the RGB light up the colors you want.
3.4. Projects
81
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 ...