netemera prs

Dependencies:   mbed

main.cpp

Committer:
yabool2001
Date:
2019-03-26
Revision:
1:db05ea2d0fe7
Parent:
0:9dffac13db39
Child:
2:9342176884e3

File content as of revision 1:db05ea2d0fe7:

#include "mbed.h"

Serial serial ( PA_9 , NC );

DigitalOut led_blue ( PA_5 );
DigitalOut led_red ( PA_8 );
DigitalOut led_orange ( PA_10 );

DigitalIn pulse ( PA_2 );
DigitalIn pulse_safe ( PB_5 );
DigitalIn flow_dir ( PB_9 );
DigitalIn case_open ( PA_3 );
DigitalIn sw1 ( PB_2 );
DigitalIn sw2 ( PB_6 );
DigitalIn sw3 ( PB_7 );

InterruptIn int_pa_0 ( PA_0 );

// Toggle LED
void toggle_led ()
{
    serial .printf ( "int_pa_0 happened!:\n\r" );
    wait (0.1); 
    if ( pulse == 1 )       led_blue = !led_blue;
    if ( pulse_safe == 1 )  led_red = !led_red;
    if ( flow_dir == 1 )    led_orange = !led_orange;
}

int main() {

    //DIP switch pin set the mode to Pull Up
    sw1 .mode (PullUp);
    sw2 .mode (PullUp);
    sw3 .mode (PullUp);

    led_blue    = 1;
    led_red     = 1;
    led_orange  = 1;

    // Change LEDs blinking frequency when pulse
    int_pa_0.rise ( &toggle_led );

    while ( 1 )
    {
        wait ( 0.5 );

        serial.printf ( "DIP switch status:\n\r" );
        ( sw1 ) ? serial .printf ( "SW1 = 1\n\r" ) : serial .printf ( "SW1 = 0\n\r" );
        ( sw2 ) ? serial .printf ( "SW2 = 1\n\r" ) : serial .printf ( "SW2 = 0\n\r" );
        ( sw3 ) ? serial .printf ( "SW3 = 1\n\r" ) : serial .printf ( "SW3 = 0\n\r" );

        serial.printf ( "Pulse status:\n\r" );
        ( pulse )       ? serial .printf ( "pulse = 1\n\r" )         : serial .printf ( "pulse = 0\n\r" );
        ( pulse_safe )  ? serial .printf ( "pulse_safe = 1\n\r" )    : serial .printf ( "pulse_safe = 0\n\r" );
        ( flow_dir )    ? serial .printf ( "flow_dir = 1\n\r" )      : serial .printf ( "flow_dir = 0\n\r" );
    }
}