Created
December 8, 2021 19:59
-
-
Save Sharkbyteprojects/61c34b4e05a6a6ea9a6cc680c9c65152 to your computer and use it in GitHub Desktop.
Music Player for Calleope
This file contains 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
#define _GNU_SOURCE | |
/* | |
* Star Wars first Music section for Calliope | |
* <c> Sharkbyteprojects | |
*/ | |
typedef unsigned int uint; | |
#include "MicroBit.h" | |
#include "NEPODefs.h" | |
#include <list> | |
#include <array> | |
#include <stdlib.h> | |
MicroBit _uBit; | |
#define c 261 | |
#define d 294 | |
#define e 329 | |
#define f 349 | |
#define g 391 | |
#define gS 415 | |
#define a 440 | |
#define aS 455 | |
#define b 466 | |
#define cH 523 | |
#define cSH 554 | |
#define dH 587 | |
#define dSH 622 | |
#define eH 659 | |
#define fH 698 | |
#define fSH 740 | |
#define gH 784 | |
#define gSH 830 | |
#define aH 880 | |
#define delay(x) _uBit.sleep(x); | |
class tone{ | |
private: | |
uint tonet; | |
uint dur; | |
uint paus; | |
uint repeat; | |
public: | |
tone(uint toneid, uint duration, uint pauseAfter = 0, uint r=0){ | |
tonet=toneid; | |
dur=duration; | |
paus=pauseAfter; | |
repeat=1+r; | |
} | |
void playTone(){ | |
for(uint x{0};x<repeat;x++){ | |
_uBit.soundmotor.soundOn(tonet); | |
delay(dur); | |
_uBit.soundmotor.soundOff(); | |
if(paus!=0) | |
delay(paus); | |
} | |
} | |
}; | |
#define n tone | |
void playSection(tone* t, size_t size){ | |
for(size_t s{0};s<size;s++){ | |
t[s].playTone(); | |
} | |
} | |
//STAR WARS SECTIONS | |
#define sizeofFirstSection 14 | |
// DIE GRößE DER SECTION MUSS FESTSTEHEN FÜR DEN PLAYER! KANN IM NACHHINEIN GEZÄHLT WERDEN | |
tone firstSection[sizeofFirstSection]={ | |
n(a, 500, 50, 2), n(f, 350, 50), | |
n(cH, 150, 50), n(a, 500, 50), | |
n(f, 350, 50), n(cH, 150, 50), | |
n(a, 650, 550), | |
n(eH, 500, 50, 2), n(fH, 350, 50), | |
n(cH, 150, 50), n(gS, 500, 50), | |
n(f, 350, 50), n(cH, 150, 50), | |
n(a, 650, 550) | |
}; | |
void start(){} | |
void loop(){ | |
playSection(&firstSection[0], sizeofFirstSection); | |
} | |
int main() | |
{ | |
_uBit.init(); | |
start(); | |
while ( true ) { | |
loop(); | |
_uBit.sleep(_ITERATION_SLEEP_TIMEOUT); | |
} | |
release_fiber(); | |
} |
This file contains 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
#define _GNU_SOURCE | |
/* <c> Sharkbyteprojects START AND LOOP = Z.66*/ | |
typedef unsigned int uint; | |
#include "MicroBit.h" | |
#include "NEPODefs.h" | |
#include <list> | |
#include <array> | |
#include <stdlib.h> | |
MicroBit _uBit; | |
//NOTEN DEF | |
#define c 261 | |
#define d 294 | |
#define e 329 | |
#define f 349 | |
#define g 391 | |
#define gS 415 | |
#define a 440 | |
#define aS 455 | |
#define b 466 | |
#define cH 523 | |
#define cSH 554 | |
#define dH 587 | |
#define dSH 622 | |
#define eH 659 | |
#define fH 698 | |
#define fSH 740 | |
#define gH 784 | |
#define gSH 830 | |
#define aH 880 | |
#define delay(x) _uBit.sleep(x); | |
class tone{ | |
private: | |
uint tonet; | |
uint dur; | |
uint paus; | |
uint repeat; | |
public: | |
tone(uint toneid, uint duration, uint pauseAfter = 0, uint r=0){ | |
tonet=toneid; | |
dur=duration; | |
paus=pauseAfter; | |
repeat=1+r; | |
} | |
void playTone(){ | |
for(uint x{0};x<repeat;x++){ | |
_uBit.soundmotor.soundOn(tonet); | |
delay(dur); | |
_uBit.soundmotor.soundOff(); | |
if(paus!=0) | |
delay(paus); | |
} | |
} | |
}; | |
#define n tone | |
//size calc: (sizeof(t) / sizeof(tone)) | |
void playSection(tone* t, size_t size){ | |
for(size_t s{0};s<size;s++){ | |
t[s].playTone(); | |
} | |
} | |
void start(){ | |
//INITIALIZE | |
} | |
void loop(){ | |
//LOOPING | |
} | |
int main() | |
{ | |
_uBit.init(); | |
start(); | |
while ( true ) { | |
loop(); | |
_uBit.sleep(_ITERATION_SLEEP_TIMEOUT); | |
} | |
release_fiber(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment