Project 10: Cheep - Thames & Kosmos Code Gamer Experiment Manual

Coding workshop ? game with kosmobits
Table of Contents

Advertisement

PROJECT 10
Cheep!
You can also use the interaction board to produce sounds.
This little project will show you how it works.
YOU WILL NEED
› KosmoDuino in the interaction board
THE PLAN
So far, the KosmoDuino just beeps at regular intervals.
Don't worry — you will learn how to turn it into a siren or
even a musical instrument.
THE PROGRAM
Start by including the
defining the
buzzerPin
pin to which the "buzzer" (the miniature speaker) is
connected.
This time, you won't have to do anything in
The composition of the
familiar to you. It matches the "Blink" program, which
was the very first program that you uploaded to your
KosmoDuino. But this time, instead of making an LED
blink, you will be making sounds. These two commands
will help:
tone(buzzerPin, 440);
frequency of 440 Hz. This is the standard pitch of A. The
tone stays on until you switch it off again with
noTone(buzzerPin);
at regular intervals, use
second pause to each of these commands.
38
CodeGamer manual inside english.indd 38
file and
KosmoBits_Pins.h
constant in order to address the
setup()
loop()
will probably look
produces a tone with a
To switch the tone on and off again
delay(500);
to attach a half-
#include <KosmoBits_Pins.h>
const int buzzerPin = KOSMOBITS_BUZZER_PIN;
.
void setup() {
// Nothing to do.
}
void loop() {
tone(buzzerPin, 440);
delay(500);
noTone(buzzerPin);
delay(500);
}
</>
7/19/16 12:32 PM

Advertisement

Table of Contents
loading

Table of Contents