Vous êtes sur la page 1sur 12

#include <IRremote.

h>
#include "pt.h"
#include "timer.h"

int RECV_PIN = 2;

IRrecv irrecv(RECV_PIN);
decode_results results;

// atentie: mai intai trebuie vazute care sunt adresele in hexa a semnalelor emise
de telecomanda
#define BUTTON_plus 0x77 // porneste sistemul si canta Track 0: Joy to the World
#define BUTTON_minus 0x876 // opreste sistemul
#define BUTTON_1 0x72 // merge instalatia 1 si canta Track 1: We Wish you a
Merry Christmas
#define BUTTON_2 0x859 // merge instalatia 2 si canta Track 2: Jingle Bells

int in1 = 7;
int in2 = 6;
int tonePin = 11;

// astea sunt pt melodii


// Define the protothreads, and also the flags that terminate the respective
protothread
// Could be abstracted into an array/stack
boolean enablePtJoyToTheWorld = true;
static struct pt ptJoyToTheWorld;
boolean enablePtWeWishYouAMerry = true;
static struct pt ptWeWishYouAMerry;
boolean enablePtJingleBells = true;
static struct pt ptJingleBells;

void setup()
{ // pt ca releu e alimentat extern de arduino se alege logica inversa
// initializez ambele relee ca fiind decuplate
pinMode(in1, OUTPUT);
digitalWrite(in1, HIGH); // pe high e decuplat
pinMode(in2, OUTPUT);
digitalWrite(in2, HIGH);
// Setup the Protothread Variables, tot pt melodii
PT_INIT(&ptJoyToTheWorld);
PT_INIT(&ptWeWishYouAMerry);
PT_INIT(&ptJingleBells);

irrecv.enableIRIn();
}

//JoyToTheWorld
// Sounds spectacularly similar to another infamous tune...
static PT_THREAD(protothreadJoyToTheWorld(struct pt *pt)) {
static struct timer tJoyToTheWorld;
PT_BEGIN(pt);
while (enablePtJoyToTheWorld) {
tone(tonePin, 587, 450.0);
timer_set(&tJoyToTheWorld, 500.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 554, 337.5);
timer_set(&tJoyToTheWorld, 375.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 493, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 440, 675.0);
timer_set(&tJoyToTheWorld, 750.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 391, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 450.0);
timer_set(&tJoyToTheWorld, 500.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 329, 450.0);
timer_set(&tJoyToTheWorld, 500.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 293, 675.0);
timer_set(&tJoyToTheWorld, 750.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 440, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 493, 670.3125);
timer_set(&tJoyToTheWorld, 744.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 493, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 554, 670.3125);
timer_set(&tJoyToTheWorld, 744.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 554, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 587, 670.3125);
timer_set(&tJoyToTheWorld, 744.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 587, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 587, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 554, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 493, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 440, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 440, 337.5);
timer_set(&tJoyToTheWorld, 375.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 391, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 587, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 587, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 554, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 493, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 440, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 440, 337.5);
timer_set(&tJoyToTheWorld, 375.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 391, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 391, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 440, 675.0);
timer_set(&tJoyToTheWorld, 750.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 391, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 329, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 329, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 329, 220.3125);
timer_set(&tJoyToTheWorld, 244.791666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
timer_set(&tJoyToTheWorld, 5.20833333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 329, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 391, 675.0);
timer_set(&tJoyToTheWorld, 750.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 329, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 293, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 587, 450.0);
timer_set(&tJoyToTheWorld, 500.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 493, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 440, 337.5);
timer_set(&tJoyToTheWorld, 375.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 391, 112.5);
timer_set(&tJoyToTheWorld, 125.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 391, 225.0);
timer_set(&tJoyToTheWorld, 250.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 369, 450.0);
timer_set(&tJoyToTheWorld, 500.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));
tone(tonePin, 329, 450.0);
timer_set(&tJoyToTheWorld, 500.0); PT_WAIT_UNTIL(pt,
timer_expired(&tJoyToTheWorld));

}
PT_END(pt);
}

// WeWishYouAMerry
static PT_THREAD(protothreadWeWishYouAMerry(struct pt *pt)) {
static struct timer tWeWishYouAMerry;
PT_BEGIN(pt);
while (enablePtWeWishYouAMerry) {
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 311, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 466, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 391, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 349, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 349, 234.374625);
timer_set(&tWeWishYouAMerry, 260.41625); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 349, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 466, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 466, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 523, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 466, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 391, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 311, 234.374625);
timer_set(&tWeWishYouAMerry, 260.41625); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 311, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 523, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 523, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 554, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 523, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 466, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 349, 234.374625);
timer_set(&tWeWishYouAMerry, 260.41625); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 311, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 311, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 349, 234.374625);
timer_set(&tWeWishYouAMerry, 260.41625); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 466, 234.374625);
timer_set(&tWeWishYouAMerry, 260.41625); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 391, 234.374625);
timer_set(&tWeWishYouAMerry, 260.41625); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 546.874125);
timer_set(&tWeWishYouAMerry, 607.637916667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 311, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 391, 624.999);
timer_set(&tWeWishYouAMerry, 694.443333333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 391, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 391, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 349, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 311, 546.874125);
timer_set(&tWeWishYouAMerry, 607.637916667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 466, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 523, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 466, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 622, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 311, 312.4995);
timer_set(&tWeWishYouAMerry, 347.221666667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 311, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 311, 156.24975);
timer_set(&tWeWishYouAMerry, 173.610833333); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 349, 234.374625);
timer_set(&tWeWishYouAMerry, 260.41625); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 466, 234.374625);
timer_set(&tWeWishYouAMerry, 260.41625); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 391, 234.374625);
timer_set(&tWeWishYouAMerry, 260.41625); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
timer_set(&tWeWishYouAMerry, 86.8054166667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
tone(tonePin, 415, 546.874125);
timer_set(&tWeWishYouAMerry, 607.637916667); PT_WAIT_UNTIL(pt,
timer_expired(&tWeWishYouAMerry));
}
PT_END(pt);
}

// JingleBells
static PT_THREAD(protothreadJingleBells(struct pt *pt)) {
static struct timer tJingleBells;
PT_BEGIN(pt);
while (enablePtJingleBells) {
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 416.6655);
timer_set(&tJingleBells, 462.961666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 416.6655);
timer_set(&tJingleBells, 462.961666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 587, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 391, 312.499125);
timer_set(&tJingleBells, 347.22125); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 440, 104.166375);
timer_set(&tJingleBells, 115.740416667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 833.331);
timer_set(&tJingleBells, 925.923333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 312.499125);
timer_set(&tJingleBells, 347.22125); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 104.166375);
timer_set(&tJingleBells, 115.740416667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 104.166375);
timer_set(&tJingleBells, 115.740416667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 104.166375);
timer_set(&tJingleBells, 115.740416667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 440, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 440, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 440, 416.6655);
timer_set(&tJingleBells, 462.961666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 587, 416.6655);
timer_set(&tJingleBells, 462.961666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 416.6655);
timer_set(&tJingleBells, 462.961666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 416.6655);
timer_set(&tJingleBells, 462.961666667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 587, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 391, 312.499125);
timer_set(&tJingleBells, 347.22125); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 440, 104.166375);
timer_set(&tJingleBells, 115.740416667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 833.331);
timer_set(&tJingleBells, 925.923333333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 312.499125);
timer_set(&tJingleBells, 347.22125); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 104.166375);
timer_set(&tJingleBells, 115.740416667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 104.166375);
timer_set(&tJingleBells, 115.740416667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 493, 104.166375);
timer_set(&tJingleBells, 115.740416667); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 587, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 587, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 523, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 440, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 391, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 587, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
tone(tonePin, 783, 208.33275);
timer_set(&tJingleBells, 231.480833333); PT_WAIT_UNTIL(pt,
timer_expired(&tJingleBells));
}
PT_END(pt);
}

void loop() {

if (irrecv.decode(&results))
{
if (results.value == BUTTON_plus)
{
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
protothreadJoyToTheWorld(&ptJoyToTheWorld);

}
if (results.value == BUTTON_minus)
{
digitalWrite(in1, HIGH);
digitalWrite(in2, HIGH);
}
if (results.value == BUTTON_1)
{
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
protothreadWeWishYouAMerry(&ptWeWishYouAMerry);
}
if (results.value == BUTTON_2)
{
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
protothreadJingleBells(&ptJingleBells);
}

irrecv.resume();
}
}

Vous aimerez peut-être aussi