Can you hear me
-
Upload
geekinlibrariansclothing -
Category
Education
-
view
11 -
download
1
Transcript of Can you hear me
![Page 1: Can you hear me](https://reader036.fdocuments.in/reader036/viewer/2022071815/55a9f46a1a28ab581c8b460b/html5/thumbnails/1.jpg)
2-2: Sound
Objectives:
Create a circuit whose state can be detected Use Scratch to play a sound when the button is pressed
This session leverages ScratchGPIO and basic principles from http://simplesi.net/scratchgpio/scratchgpio-1st-project. If you have not installed
this on the kits already, please do so.
Counting pins on the breakout board becomes important here. Start from the
top left (3V3, row 1) and count ACROSS then DOWN. 3V3 is pin 1, 5V on the other side is pin 2, SDA in row 2 is pin 3, the second 5V on the other side is pin 4,
SCL is pin 5, GND in row 3 is pin 6, and so on. There are 26 pins on the model B
breakout.
Connect headphones to the Pi. Log on to the Pi, and start the X Windows System via the startx command. Launch ScratchGPIO6. Start by making sure
Scratch can play a sound. Drag the “play sound” element to the script area,
and click it . You should hear the sound (meow by default).
Now let 's create a circuit to control the sound. All we really need is a button.
Wire pin 7 (which is confusingly labeled P4) to 28A Put a switch in 28E and 30E
Wire 30A to - Wire – to GND (13A)
In order to tell what the button is doing, we need to check it periodically. Put the following script together:
Start with a “forever” from the Control category Inside the forever, place a “say … for 2 secs” from the Looks category
Inside the say, place a “slider sensor value” from the Sensing category Change the “slider” in the sensor value to “pin7”
Click the forever to start it . It should say 1 when the button is not pressed, 0 when the button is pressed. Now that we know how to detect what the button
is doing, let 's connect the pieces together.
Start with a “forever if” from the Control category
Inside the condit ion of the “if … then” place a “< _ = _ >” operator from the Operators category
On one side of the equals operator, put the number zero.
On the other side of the equals operator, put the “pin7 sensor value” from
![Page 2: Can you hear me](https://reader036.fdocuments.in/reader036/viewer/2022071815/55a9f46a1a28ab581c8b460b/html5/thumbnails/2.jpg)
the Sensing category
Inside the body of the “forever if” place a “play sound” from the Sound category
Customize the sound if you like. If you want a visual indicator as well, place a
“say … for 2 secs” from the Looks category in the body of the “forever if” block.
Congratulations, you have a working button that does something useful!
Tear down as normal. Make sure all the components stay with their kits.