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
Содержание Thales Kit
Страница 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Страница 10: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 6 Chapter 1 Introduction to Raspberry Pi Pico ...
Страница 12: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 8 Chapter 2 What is Included in This Kit ...
Страница 13: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 1 Components List 2 1 Components List 9 ...
Страница 42: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 38 Chapter 2 What is Included in This Kit ...
Страница 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Страница 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...