Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions examples/sound_music/CPmelody/CPmelody.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Adafruit Circuit Playground - Melody Support Open Source, buy at Adafruit
// 2016-08-06 Version 1 by Mike Barela for Adafruit Industries
// Adapted from melody by Tom Igoe on arduino.cc
// Uses the CircuitPlayground library to easily use the full functionality of the board

#include <Adafruit_CircuitPlayground.h>
#include "pitches.h"

const int numNotes = 8; // number of notes we are playing
int melody[] = { // specific notes in the melody
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 };

int noteDurations[] = { // note durations: 4 = quarter note, 8 = eighth note, etc.:
4, 8, 8, 4, 4, 4, 4, 4 };

void setup() {
CircuitPlayground.begin(); // initialize the CP library
}

void loop() {
if(CircuitPlayground.rightButton()) { // play when we press the right button
for (int thisNote = 0; thisNote < numNotes; thisNote++) { // play notes of the melody
// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
CircuitPlayground.playTone(melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
}
}
}
93 changes: 93 additions & 0 deletions examples/sound_music/CPmelody/pitches.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*************************************************
* Musical Notes via https://www.arduino.cc/en/Tutorial/ToneMelody
*************************************************/

#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
25 changes: 25 additions & 0 deletions examples/sound_music/CPmove2sound/CPmove2sound.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Adafruit Circuit Playground - Movement to Sound Support Open Source, buy Adafruit
// 2016-08-07 Version 1 by Mike Barela for Adafruit Industries
// Uses the CircuitPlayground library to easily use the full functionality of the board

#include <Adafruit_CircuitPlayground.h>

void setup() {
CircuitPlayground.begin(); // initialize the Circuit Playground library
Serial.begin(9600);
}

void loop() {
float movementX, movementY, movementZ, movement;
uint16_t sound;
if(CircuitPlayground.slideSwitch()) { // sense & play when slide whitch at "+"
movementX = abs(CircuitPlayground.motionX()); // read the X motion (absolute value)
movementY = abs(CircuitPlayground.motionY()); // read the Y motion (absolute value)
movementZ = abs(CircuitPlayground.motionZ()); // read the Z motion (absolute value)
movement = movementX + movementY + movementZ; // aggregate the movement sensed
Serial.println(movement);
sound = (int) map(movement, 8.0, 60.0, 440.0, 1760.0); // map movement to music values
CircuitPlayground.playTone(sound, 500); // play sound for 500 milliseconds
}
}

31 changes: 31 additions & 0 deletions examples/sound_music/CPtemp2sound/CPtemp2sound.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Adafruit Circuit Playground - Temperature to Sound Support Open Source, buy Adafruit
// 2016-08-07 Version 1 by Mike Barela for Adafruit Industries
// Uses the CircuitPlayground library to easily use the full functionality of the board

#include <Adafruit_CircuitPlayground.h>

const float alertTemp = 90.0; // temperature to alert on (use 32.0 for a freezer etc.)

void setup() {
CircuitPlayground.begin(); // initialize the Circuit Playground library
Serial.begin(9600);
}

void loop() {
float temp;
uint16_t sound;
if(CircuitPlayground.slideSwitch()) { // if the slide switch is at "+"
temp = CircuitPlayground.temperatureF(); // read the light sensor
Serial.println(temp);
sound = (int) map(temp, 70.0, 100.0, 131.0, 1760.0); // map light to music values
CircuitPlayground.playTone(sound, 100); // play sound for 100 milliseconds
}
else { // switch set to "-" for absolute temperature measurement
temp = CircuitPlayground.temperatureF(); // read the light sensor
Serial.println(temp);
if( temp > alertTemp ) { // if the read temperature is > your prepicked alartTemp
CircuitPlayground.playTone(3520, 100); // play sound for 100 milliseconds
}
}
}

82 changes: 82 additions & 0 deletions examples/sound_music/CPtheme/CPtheme.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Adafruit Circuit Playground - Theme Song Support Open Source, buy at Adafruit
// 2016-08-06 Version 1 by Mike Barela for Adafruit Industries
// Adapted from melody by Tom Igoe on arduino.cc
// Uses the CircuitPlayground library to easily use the full functionality of the board

#include <Adafruit_CircuitPlayground.h>
#include "pitches.h"

int melody[] = { // specific notes in the melody
NOTE_E7, NOTE_E7, 0, NOTE_E7,
0, NOTE_C7, NOTE_E7, 0,
NOTE_G7, 0, 0, 0,
NOTE_G6, 0, 0, 0,

NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,

NOTE_G6, NOTE_E7, NOTE_G7,
NOTE_A7, 0, NOTE_F7, NOTE_G7,
0, NOTE_E7, 0, NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0,

NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,

NOTE_G6, NOTE_E7, NOTE_G7,
NOTE_A7, 0, NOTE_F7, NOTE_G7,
0, NOTE_E7, 0, NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0
};
int numNotes; // Number of notes in the melody

int noteDurations[] = { // note durations
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,

12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,

9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,

12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,

9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
};

void setup() {
CircuitPlayground.begin(); // initialize the CP library
numNotes = sizeof(melody)/sizeof(int); // number of notes we are playing
}

void loop() {
if(CircuitPlayground.rightButton()) { // play when we press the right button
for (int thisNote = 0; thisNote < numNotes; thisNote++) { // play notes of the melody
// to calculate the note duration, take one second divided by the note type.
int noteDuration = 1000 / noteDurations[thisNote];
CircuitPlayground.playTone(melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
}
}
}
93 changes: 93 additions & 0 deletions examples/sound_music/CPtheme/pitches.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*************************************************
* Musical Notes via https://www.arduino.cc/en/Tutorial/ToneMelody
*************************************************/

#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
19 changes: 19 additions & 0 deletions examples/sound_music/CPtheremin/CPtheremin.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Adafruit Circuit Playground - Light Theremin Support Open Source, buy at Adafruit
// 2016-08-07 Version 1 by Mike Barela for Adafruit Industries
// Uses the CircuitPlayground library to easily use the full functionality of the board

#include <Adafruit_CircuitPlayground.h>

void setup() {
CircuitPlayground.begin(); // initialize the Circuit Playground library
}

void loop() {
int value , sound;
if(CircuitPlayground.slideSwitch()) { // if the slide switch is on
value = CircuitPlayground.lightSensor(); // read the light sensor
sound = map(value, 5, 1000, 131, 1760); // map light values to music values
CircuitPlayground.playTone(sound, 100); // play sound for 100 milliseconds
}
}

Loading