Created
July 10, 2019 04:35
-
-
Save uXeBoy/630cf20acf3a87803a4a94cce48e708c to your computer and use it in GitHub Desktop.
BeepTest.ino
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
#include <Arduboy2.h> | |
Arduboy2 arduboy; | |
BeepPin1 beep1; | |
BeepPin2 beep2; | |
static bool tonesPlaying = false; | |
static uint8_t duration = 0; | |
static uint8_t *tonesStart = 0; | |
static uint8_t *tonesIndex = 0; | |
const uint8_t DK_climbing_ladders[] = | |
{ | |
0x60, 0xCA, 0x82, 0x20, 0xCC, 0x84, 0x40, 0xD0, 0x86, 0x40, 0xCA, 0x82, 0x08, 0xDA, 0x89, 0x08, 0xD9, 0x89, | |
0x08, 0xDA, 0x89, 0x08, 0xD9, 0x89, 0x08, 0xDA, 0x89, 0x08, 0xD9, 0x89, 0x08, 0xDA, 0x89, 0x08, 0xD9, 0x89, | |
0x08, 0xDA, 0x89, 0x08, 0xD9, 0x89, 0x08, 0xDA, 0x89, 0x08, 0xD9, 0x89, 0x08, 0xDA, 0x89, 0x08, 0xD9, 0x89, | |
0x08, 0xDA, 0x89, 0x08, 0xD9, 0x89, 0x7F, 0xDA, 0x8A, | |
0x00 | |
}; | |
const float freqKong[] = | |
{ | |
220, 233.08, 246.94, 261.63, 277.18, 293.67, 311.13, 329.63, 349.23, 369.99, 392, 415.3, | |
110, 116.54, 123.47, 130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185, 196, 207.65 | |
}; | |
void toneKong(uint8_t *tones) | |
{ | |
uint8_t temp, freqIndex; | |
tonesStart = tonesIndex = tones; // set to start of sequence array | |
duration = *tonesIndex++; | |
temp = *tonesIndex++; | |
freqIndex = (temp & 0x0F) + (((temp & B00110000) >> 4) * 12); | |
beep1.tone(beep1.freq(freqKong[freqIndex])); | |
if ((*tonesIndex & B11000000)) | |
{ | |
temp = *tonesIndex++; | |
freqIndex = (temp & 0x0F) + (((temp & B00110000) >> 4) * 12); | |
beep2.tone(beep2.freq(freqKong[freqIndex])); | |
} | |
tonesPlaying = true; | |
} | |
void timerKong() | |
{ | |
uint8_t temp, freqIndex; | |
if (duration == 0) | |
{ | |
if (tonesPlaying) | |
{ | |
temp = *tonesIndex++; | |
if (temp == 0) | |
{ | |
tonesPlaying = false; // "end of sequence" marker | |
} | |
else | |
{ | |
duration = temp; | |
temp = *tonesIndex++; | |
freqIndex = (temp & 0x0F) + (((temp & B00110000) >> 4) * 12); | |
if ((temp & 0x0F) == 12) // NOTE_REST | |
{ | |
beep1.noTone(); | |
} | |
else | |
{ | |
beep1.tone(beep1.freq(freqKong[freqIndex])); | |
} | |
if ((*tonesIndex & B11000000)) | |
{ | |
temp = *tonesIndex++; | |
freqIndex = (temp & 0x0F) + (((temp & B00110000) >> 4) * 12); | |
if ((temp & 0x0F) == 12) // NOTE_REST | |
{ | |
beep2.noTone(); | |
} | |
else | |
{ | |
beep2.tone(beep2.freq(freqKong[freqIndex])); | |
} | |
} | |
} | |
} | |
} | |
else if (--duration == 0) | |
{ | |
beep1.noTone(); | |
beep2.noTone(); | |
} | |
} | |
void setup() | |
{ | |
arduboy.begin(); | |
arduboy.setFrameRate(120); | |
beep1.begin(); | |
beep2.begin(); | |
toneKong(DK_climbing_ladders); | |
} | |
void loop() | |
{ | |
if (!arduboy.nextFrame()) | |
{ | |
return; | |
} | |
timerKong(); // handle tone duration | |
if (!tonesPlaying) | |
{ | |
toneKong(DK_climbing_ladders); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment