4180 lab 5

Dependencies:   mbed 4DGL-uLCD-SE RPCInterface

main.cpp

Committer:
emilywilson
Date:
2020-02-19
Revision:
2:4845e2dae429
Parent:
0:bdbd3d6fc5d5
Child:
3:94d9434576af

File content as of revision 2:4845e2dae429:

#include "mbed.h"
#include "rtos.h"
//#include "part2.h"
//#include "part3.h"
#include "part4_led.h"
//#include "lidar_theremin.h"

Serial pc(USBTX, USBRX);
RawSerial  dev(p13,p14);

DigitalOut myled1(LED1);
RGBLed led = RGBLed(p21, p22, p23);
Color colors[] = { _red, _pink, _orange, _yellow };

Thread led_thread;

void changeColor(char c) {
    if (c == 'r') {
        colors[0] = _red;
        colors[1] = _pink;
        colors[2] = _orange;
        colors[3] = _yellow;
    } else if (c == 'b') {
        colors[0] = _teal;
        colors[1] = _light_blue;
        colors[2] = _blue;
        colors[3] = _purple;
    } else if (c == 'g') {
        colors[0] = _yellow;
        colors[1] = _light_green;
        colors[2] = _green;
        colors[3] = _teal;
    }
}

void led_handler() {
    Color c = colors[0];
    int i = 0;
    while (1) {
        led.write(c.red, c.green, c.blue);
        i = (i + 1) % 4;
        c = colors[i];
        
        Thread::wait(500);
    }
}

int main() {
//    run_part2();
//    run_part2_EC();
//    run_lidar_theremin();
    
//    run_part3();
    
    led_thread.start(led_handler);

    while (1) {
        myled1 = !myled1;
        
        if (dev.readable()) {
//            changeColor(dev.getc());
            pc.putc(dev.getc());
        }

        Thread::wait(500);
    }
}