music mixer code

Dependencies:   mbed wave_player mbed-rtos SimpleRGB 4DGL-uLCD-SE PinDetect

main.cpp

Committer:
kswanson31
Date:
2016-10-10
Revision:
1:ff69d2d97a2c
Parent:
0:51d88b4e2b23
Child:
2:c64bfb83fe76

File content as of revision 1:ff69d2d97a2c:

#include "mbed.h"
#include "rtos.h"
#include "SimpleRGB.h"

#define SECOND 1000 // used with threads

/* 1 init/declare

Ticker first;
Ticker second;
Ticker third;
Ticker fourth;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

void one() {      // attached to ticker object. will be called after time given
    led1 = !led1; // flip the value of the led
}                 // nothing returned

void two() {
    led2 = !led2;
}

void three() {
    led3 = !led3;
}

void fourth() {
    led4 = !led4;
}

*/// - 1


/* 2 init/declare */

// lcd thread
void uLCD_reboot_thread(void const *args) {
    // show reboot process, associated with clip of apple restart
    while (true) {
        // lock, print 'Rebooting!' to uLCD with "progress_bar" underneath
        // draw progress bar 8 sec
        // draw an ascii 'apple'
        // unlock, wait for 52
    }
}

// lcd thread
void uLCD_status_thread(void const *args) {
    // show time with smile, frown, sad face at top right
    while (true) {
        // lock, update time at top right with smiley at top left
        // unlock, wait for 20 sec
        // lock, change to frown
        // unlock, wait for 20 sec
        // lock, change to sad
        // unlock, wait for 20 sec
    }
}

RGBLed rgbLED(p21, p22, p23);          // object to use the RGB LED
const LightColor green(0.0, 0.8, 0.0); // adjust brightness for green
const LightColor yellow(1.0, 0.8, 0.0);
const LightColor orange(1.0, 0.4, 0.0);
const LightColor red(1.0,0.0,0.0);
const LightColor violet(1.0, 0.0, 0.8);
const LightColor blue(0.0, 0.0, 1.0);

// rgb led thread
void rainbow_led_thread(void const *args) {
    // reboot with white (6 sec), then cycle through apple colors (54 sec)
    while (true) {
        rgbLED.write(1.0, 1.0, 1.0); // bright white
        Thread::wait(2 * SECOND);
        // dim to nothing over 4 seconds
        for (float c = 1.0; c > 0.0; c = c - 0.01) {
            rgbLED.write(c, c, c);
            Thread::wait(40); // 40 * 100 = 4000 = 4 secs
        }
        // rotate through other colors over 54 seconds
        rgbLED = green;
        Thread::wait(9 * SECOND);
        rgbLED = yellow;
        Thread::wait(9 * SECOND);
        rgbLED = orange;
        Thread::wait(9 * SECOND);
        rgbLED = red;
        Thread::wait(9 * SECOND);
        rgbLED = violet;
        Thread::wait(9 * SECOND);
        rgbLED = blue;
        Thread::wait(9 * SECOND);
    }
}
// - 2


int main() {
    /* 1 calls
    led1 = 1, led2 = 1, led3 = 1, led4 = 1;
    
    first.attach(&one, 1.0);   // attach the function and when to call it
    second.attach(&two, 2.0);
    third.attach(&three, 3.0);
    fourth.attach(&four, 4.0);
    */// - 1
    
    
    /* 2 calls */
    Thread thread2(uLCD_reboot_thread);
    Thread thread3(uLCD_status_thread);
    Thread thread4(rainbow_led_thread);
    // - 2
    
    
    while(true) {
        /* 2 speaker 'thread' calls */
        // speaker plays mac reboot sound, error sound occasionally
        // play reboot sound
        // wait 20
        // error
        // wait 20
        // error
        // wait 20
    }                // interupts will occur automatically
}