Created
January 9, 2014 21:08
-
-
Save technobly/8342067 to your computer and use it in GitHub Desktop.
Simple Tone Generator for the Spark Core
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-----------------------------------------------// | |
// SPARK CORE SIMPLE TONE GENERATOR // | |
//===============================================// | |
// Copy this into a new application at: // | |
// https://www.spark.io/build and go nuts! // | |
//-----------------------------------------------// | |
// Technobly / BDub - Jan 2014 // | |
//===============================================// | |
#define NOTE_B2 4065 | |
#define NOTE_C3 3817 | |
#define NOTE_CS3 3597 | |
#define NOTE_D3 3401 | |
#define NOTE_DS3 3205 | |
#define NOTE_E3 3030 | |
#define NOTE_F3 2857 | |
#define NOTE_FS3 2703 | |
#define NOTE_G3 2551 | |
#define NOTE_GS3 2404 | |
#define NOTE_A3 2273 | |
#define NOTE_AS3 2146 | |
#define NOTE_B3 2024 | |
#define NOTE_C4 1908 | |
#define NOTE_CS4 1805 | |
#define NOTE_D4 1701 | |
#define NOTE_DS4 1608 | |
#define NOTE_E4 1515 | |
#define NOTE_F4 1433 | |
#define NOTE_FS4 1351 | |
#define NOTE_G4 1276 | |
#define NOTE_GS4 1205 | |
#define NOTE_A4 1136 | |
#define NOTE_AS4 1073 | |
#define NOTE_B4 1012 | |
#define NOTE_C5 956 | |
#define NOTE_CS5 903 | |
#define NOTE_D5 852 | |
#define NOTE_DS5 804 | |
#define NOTE_E5 759 | |
#define NOTE_F5 716 | |
#define NOTE_FS5 676 | |
#define NOTE_G5 638 | |
#define NOTE_GS5 602 | |
#define NOTE_A5 568 | |
#define NOTE_AS5 536 | |
#define NOTE_B5 506 | |
#define NOTE_C6 478 | |
#define NOTE_CS6 451 | |
#define NOTE_D6 426 | |
#define NOTE_DS6 402 | |
#define NOTE_E6 379 | |
#define NOTE_F6 358 | |
#define NOTE_FS6 338 | |
#define NOTE_G6 319 | |
#define NOTE_GS6 301 | |
#define NOTE_A6 284 | |
#define NOTE_AS6 268 | |
#define NOTE_B6 253 | |
#define NOTE_C7 239 | |
#define NOTE_CS7 226 | |
#define NOTE_D7 213 | |
#define NOTE_DS7 201 | |
#define NOTE_E7 190 | |
#define NOTE_F7 179 | |
#define NOTE_FS7 169 | |
#define NOTE_G7 159 | |
#define NOTE_GS7 151 | |
#define NOTE_A7 142 | |
#define NOTE_AS7 134 | |
#define NOTE_B7 127 | |
#define NOTE_C8 119 | |
#define NOTE_CS8 113 | |
#define NOTE_D8 106 | |
#define NOTE_DS8 100 | |
#define DURATION 1000000 // in microseconds | |
#define MAX_NOTES 65 | |
int note[MAX_NOTES] = | |
{4065,3817,3597,3401,3205,3030,2857,2703,2551,2404,2273, | |
2146,2024,1908,1805,1701,1608,1515,1433,1351,1276,1205, | |
1136,1073,1012,956,903,852,804,759,716,676,638,602,568, | |
536,506,478,451,426,402,379,358,338,319,301,284,268,253, | |
239,226,213,201,190,179,169,159,151,142,134,127,119,113,106,100}; | |
int16_t pin = D6; | |
int16_t x,y = 0; | |
void setup() { | |
pinMode(pin,OUTPUT); | |
} | |
void loop() { | |
for(x=0;x<(DURATION/note[y]);x++) { | |
PIN_MAP[pin].gpio_peripheral->BSRR = PIN_MAP[pin].gpio_pin; // HIGH | |
delayMicroseconds(note[y]); | |
PIN_MAP[pin].gpio_peripheral->BRR = PIN_MAP[pin].gpio_pin; // LOW | |
delayMicroseconds(note[y]); | |
} | |
y++; | |
if(y>=MAX_NOTES) y=0; | |
delay(250); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment