SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
(continued from previous page)
light_low
=
65535
light_high
=
0
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
tone
(pin,frequency,duration):
pin
.
freq(frequency)
pin
.
duty_u16(
30000
)
utime
.
sleep_ms(duration)
pin
.
duty_u16(
0
)
# calibrate the photoresistor max & min values.
timer_init_start
=
utime
.
ticks_ms()
led
.
value(
1
)
while
utime
.
ticks_diff(utime
.
ticks_ms(), timer_init_start)
<
5000
:
light_value
=
photoresistor
.
read_u16()
if
light_value
>
light_high:
light_high
=
light_value
if
light_value
<
light_low:
light_low
=
light_value
led
.
value(
0
)
# play
while
True
:
light_value
=
photoresistor
.
read_u16()
pitch
=
int
(interval_mapping(light_value,light_low,light_high,
50
,
6000
))
if
pitch
>
50
:
tone(buzzer,pitch,
20
)
utime
.
sleep_ms(
10
)
When the program runs, the LED will light up, and we will have five seconds to calibrate the detection range of the
photoresistor. This is because we may be in a different light environment each time we use it (e.g. the light intensity
is different between midday and dusk).
At this time, we need to swing our hands up and down on top of the photoresistor, and the movement range of the hand
will be calibrated to the playing range of this instrument.
After five seconds, the LED will go out and we can wave our hands on the photoresistor to play.
3.4.15 Microchip - 74HC595
Integrated circuit (integrated circuit) is a kind of miniature electronic device or component, which is represented by
the letter “IC” in the circuit.
A certain process is used to interconnect the transistors, resistors, capacitors, inductors and other components and
wiring required in a circuit, fabricate on a small or several small semiconductor wafers or dielectric substrates, and
then package them in a package , it has become a micro-structure with the required circuit functions; all of the
components have been structured as a whole, making electronic components a big step towards micro-miniaturization,
low power consumption, intelligence and high reliability.
The inventors of integrated circuits are Jack Kilby (integrated circuits based on germanium (Ge)) and Robert Norton
Noyce (integrated circuits based on silicon (Si)).
This kit is equipped with an IC, 74HC595, which can greatly save the use of GPIO pins. Specifically, it can replace 8
pins for digital signal output by writing an 8-bit binary number.
3.4. Projects
95
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 ...