Last active
August 9, 2016 06:12
-
-
Save andrewjbennett/f5c1e632cd38a3e923b4d6cb3c2f35bd to your computer and use it in GitHub Desktop.
Star Wars for the TI SensorTag cc2650 on Contiki OS
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
/** | |
* \file | |
* Messing around with music | |
* \author | |
* Andrew Bennett <andrew.bennett@unsw.edu.au> | |
*/ | |
#include "contiki.h" | |
#include "buzzer.h" | |
#include "dev/leds.h" | |
// set these however you like | |
#define NOTE_MULTIPLIER 2 | |
#define DELAY_BETWEEN_NOTES 0.10 | |
#define CLOCK_SECOND_DIVISOR 10.0 | |
#define TIMING_DIVISOR (60.0*CLOCK_SECOND_DIVISOR) | |
float timings[] = { | |
1.0, 1.0, 1.0, 0.75, 0.25, 1.0, 0.75, 0.25, 2.0, 1.0, 1.0, 1.0, 0.75, 0.25, 1.0, 0.75, 0.25, 2.0, 1.0, 0.75, 0.25, 1.0, 0.75, 0.25, 0.25, 0.25, 0.5, 0.5, 1.0, 0.75, 0.25, 0.25, 0.25, 0.5, 0.5, 1.0, 0.75, 0.25, 1.0, 0.75, 0.25, 2.0, 1.0, 0.75, 0.25, 1.0, 0.75, 0.25, 0.25, 0.25, 0.5, 0.5, 1.0, 0.75, 0.25, 0.25, 0.25, 0.5, 0.5, 1.0, 0.75, 0.25, 1.0, 0.75, 0.25, 2.0 | |
}; | |
uint16_t notes[] = { | |
440, 440, 440, 349, 523, 440, 349, 523, 440, 659, 659, 659, 698, 523, 415, 349, 523, 440, 880, 440, 440, 880, 830, 784, 739, 659, 698, 466, 622, 587, 554, 523, 493, 523, 349, 415, 349, 440, 523, 440, 523, 659, 880, 440, 440, 880, 830, 784, 739, 659, 698, 466, 622, 587, 554, 523, 493, 523, 349, 415, 349, 523, 440, 349, 523, 440 | |
}; | |
#define SONG_LEN 66 | |
// songs over 65535 won't fit in memory anyway | |
uint16_t upto = 0; | |
/*---------------------------------------------------------------------------*/ | |
PROCESS(music_process, "Music!"); | |
AUTOSTART_PROCESSES(&music_process); | |
/*---------------------------------------------------------------------------*/ | |
PROCESS_THREAD(music_process, ev, data) { | |
PROCESS_BEGIN(); | |
leds_toggle(LEDS_RED); | |
while (1) { | |
// start the buzzer at the specified pitch, multiplied by some multiplier | |
buzzer_start(notes[upto]*NOTE_MULTIPLIER); | |
// wait for the duration of the note | |
clock_wait(CLOCK_SECOND * timings[upto] / TIMING_DIVISOR); | |
// stop the buzzer | |
buzzer_stop(); | |
// wait before the next note | |
clock_wait(CLOCK_SECOND*DELAY_BETWEEN_NOTES); | |
upto++; | |
// woohoo party time | |
leds_toggle(LEDS_ALL); | |
// loop the song | |
if (upto >= SONG_LEN) { | |
upto = 0; | |
} | |
} | |
PROCESS_END(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment