J&W / Mbed OS frdm_LED_PWM

Dependencies:   tsi_sensor MMA8451Q

main.cpp

Committer:
Pythia
Date:
2020-06-07
Revision:
0:225e4447fdd3
Child:
1:1e448c750b63

File content as of revision 0:225e4447fdd3:

#include "mbed.h"
#include "LED_line.h"

enum sensor {SENSOR_ON=1, SENSOR_OFF=0} s0=SENSOR_OFF, s1=SENSOR_OFF, s2=SENSOR_OFF;

int main(void) 
{
    DigitalIn sens_0(PTC1);
    DigitalIn sens_1(PTC2);
    DigitalIn sens_2(PTB3);

    LED_line l1 (PTB0, L_LED_OFF, L_LED_ON, L_CYCLE, false);
    LED_line l2 (PTB1, L_LED_OFF, L_LED_ON, L_CYCLE, true);

    LED_line led_green(LED_GREEN, L_LED_OFF, L_LED_ON, L_CYCLE, false);
    LED_line led_red(LED_RED, L_LED_OFF, L_LED_ON, L_CYCLE, true);
    LED_line led_blue(LED_BLUE, L_LED_OFF, L_LED_ON, L_CYCLE, false);

    printf("\nStart\n");

//    unsigned long int c=0, l=0;

    while (true) 
    {
//        c++;
//        if (c >= L_CYCLE) 
//        {
//            c = 0;
//            l += RAMP_SLOPE;
//            if (l >= L_CYCLE) l = 0;
//        }

        s0 = (sens_0 == 1) ? SENSOR_ON : SENSOR_OFF;
        s1 = (sens_1 == 1) ? SENSOR_ON : SENSOR_OFF;
        s2 = (sens_2 == 1) ? SENSOR_ON : SENSOR_OFF;

//        l1.level(l);
//        l2.level(l);
        
//        led_red.level(l);
//        led_green.level(l);
//        led_blue.level(l);

        l1.LED_run();
        l2.LED_run();

        led_green.LED_run();
        led_red.LED_run();
        led_blue.LED_run();

        if (s0 == SENSOR_ON) 
        {
            led_green.light();
            l1.light();
        }
        if (s1 == SENSOR_ON) 
        {
            led_red.light();
            l1.light();
            l2.light();
        }
        if (s2 == SENSOR_ON) 
        {
            led_blue.light();
            l2.light();
        }
    }
}