In this lecture, you will...
CircuitPlayground.playTone()
By the end of this lecture, you should be able to...
For this class, we will begin looking at new ways of organizing variables: arrays. Arrays are lists of elements of the same type. We can use them to keep track of many different variables at one time. Let's illustrate this with a series of examples:
#include <Adafruit_CircuitPlayground.h>
int c4 = 261; // frequency in hz
int g4 = 392;
int a4 = 440;
int noteDur = 200;
void setup() {
CircuitPlayground.begin();
CircuitPlayground.playTone(c4, noteDur); // frequency, duration (Hz, ms)
CircuitPlayground.playTone(c4, noteDur);
CircuitPlayground.playTone(g4, noteDur);
CircuitPlayground.playTone(g4, noteDur);
CircuitPlayground.playTone(a4, noteDur);
CircuitPlayground.playTone(a4, noteDur);
CircuitPlayground.playTone(g4, noteDur);
}
void loop() {
}
#include <Adafruit_CircuitPlayground.h>
int notes[3] = {261, 392, 440};
int noteDur = 200;
void setup() {
CircuitPlayground.begin();
CircuitPlayground.playTone(notes[0], noteDur);
CircuitPlayground.playTone(notes[0], noteDur);
CircuitPlayground.playTone(notes[1], noteDur);
CircuitPlayground.playTone(notes[1], noteDur);
CircuitPlayground.playTone(notes[2], noteDur);
CircuitPlayground.playTone(notes[2], noteDur);
CircuitPlayground.playTone(notes[1], noteDur);
}
void loop() {
}