59
digitalWrite(BeepPin, LOW);
//
We use an active buzzer in this experiment, so it will
make sound automatically when connecting to the direct current. This sketch is to set
the I/O port as low level (0V), thus to manage the transistor and make the buzzer beep.
digitalWrite(BeepPin, HIGH);
// To set the I/O port as high level(5V), thus the
transistor is not energized and the buzzer
doesn’t
beep.
For Python users:
Step 2: Open the code file
cd
/
home
/
pi
/
SunFounder_Super_Kit_V3.0_for_Raspberry_Pi
/
Python
Step 3: Run
sudo
python
06_beep.py
Code Explanation
GPIO.output(BeepPin, GPIO.LOW)
# Set the buzzer pin as low level.
time.sleep(0.1)
# Wait for 0.1 second. Change the switching frequency by changing this
parameter. Note: Not the sound frequency. Active Buzzer cannot change sound frequency.
GPIO.output(BeepPin, GPIO.HIGH)
# close the buzzer
time.sleep(0.1)
Now, you should hear the buzzer make sounds.
Further Exploration
If you have a passive buzzer in hand, you can replace the active buzzer with it. Now you can
make a buzzer sound like “do re mi fa so la si do” with just some basic knowledge of
programming. Give a try!
Содержание Super Kit 3.0
Страница 7: ...4 22 RGB LED 1 23 LED red 8 24 LED white 4 25 LED green 4 26 LED yellow 4 27 NPN Transistor S8050 2 ...
Страница 30: ...27 Also we have drawn a table of the corresponding BCM wiringPi and Name of each pins ...
Страница 78: ...75 Now pull the slide and you can see the two LEDs light up alternately ...