netemera prs

Dependencies:   mbed

Committer:
yabool2001
Date:
Tue Mar 26 10:01:53 2019 +0000
Revision:
1:db05ea2d0fe7
Parent:
0:9dffac13db39
Child:
2:9342176884e3
DIP Switch Pull Up mode; UART debug messages; InterruptIn rise

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yabool2001 0:9dffac13db39 1 #include "mbed.h"
yabool2001 0:9dffac13db39 2
yabool2001 1:db05ea2d0fe7 3 Serial serial ( PA_9 , NC );
yabool2001 0:9dffac13db39 4
yabool2001 0:9dffac13db39 5 DigitalOut led_blue ( PA_5 );
yabool2001 0:9dffac13db39 6 DigitalOut led_red ( PA_8 );
yabool2001 0:9dffac13db39 7 DigitalOut led_orange ( PA_10 );
yabool2001 0:9dffac13db39 8
yabool2001 0:9dffac13db39 9 DigitalIn pulse ( PA_2 );
yabool2001 0:9dffac13db39 10 DigitalIn pulse_safe ( PB_5 );
yabool2001 0:9dffac13db39 11 DigitalIn flow_dir ( PB_9 );
yabool2001 0:9dffac13db39 12 DigitalIn case_open ( PA_3 );
yabool2001 0:9dffac13db39 13 DigitalIn sw1 ( PB_2 );
yabool2001 0:9dffac13db39 14 DigitalIn sw2 ( PB_6 );
yabool2001 0:9dffac13db39 15 DigitalIn sw3 ( PB_7 );
yabool2001 0:9dffac13db39 16
yabool2001 1:db05ea2d0fe7 17 InterruptIn int_pa_0 ( PA_0 );
yabool2001 0:9dffac13db39 18
yabool2001 0:9dffac13db39 19 // Toggle LED
yabool2001 0:9dffac13db39 20 void toggle_led ()
yabool2001 0:9dffac13db39 21 {
yabool2001 1:db05ea2d0fe7 22 serial .printf ( "int_pa_0 happened!:\n\r" );
yabool2001 1:db05ea2d0fe7 23 wait (0.1);
yabool2001 1:db05ea2d0fe7 24 if ( pulse == 1 ) led_blue = !led_blue;
yabool2001 1:db05ea2d0fe7 25 if ( pulse_safe == 1 ) led_red = !led_red;
yabool2001 1:db05ea2d0fe7 26 if ( flow_dir == 1 ) led_orange = !led_orange;
yabool2001 0:9dffac13db39 27 }
yabool2001 0:9dffac13db39 28
yabool2001 0:9dffac13db39 29 int main() {
yabool2001 0:9dffac13db39 30
yabool2001 1:db05ea2d0fe7 31 //DIP switch pin set the mode to Pull Up
yabool2001 1:db05ea2d0fe7 32 sw1 .mode (PullUp);
yabool2001 1:db05ea2d0fe7 33 sw2 .mode (PullUp);
yabool2001 1:db05ea2d0fe7 34 sw3 .mode (PullUp);
yabool2001 0:9dffac13db39 35
yabool2001 1:db05ea2d0fe7 36 led_blue = 1;
yabool2001 1:db05ea2d0fe7 37 led_red = 1;
yabool2001 1:db05ea2d0fe7 38 led_orange = 1;
yabool2001 1:db05ea2d0fe7 39
yabool2001 1:db05ea2d0fe7 40 // Change LEDs blinking frequency when pulse
yabool2001 1:db05ea2d0fe7 41 int_pa_0.rise ( &toggle_led );
yabool2001 0:9dffac13db39 42
yabool2001 0:9dffac13db39 43 while ( 1 )
yabool2001 0:9dffac13db39 44 {
yabool2001 0:9dffac13db39 45 wait ( 0.5 );
yabool2001 1:db05ea2d0fe7 46
yabool2001 0:9dffac13db39 47 serial.printf ( "DIP switch status:\n\r" );
yabool2001 1:db05ea2d0fe7 48 ( sw1 ) ? serial .printf ( "SW1 = 1\n\r" ) : serial .printf ( "SW1 = 0\n\r" );
yabool2001 1:db05ea2d0fe7 49 ( sw2 ) ? serial .printf ( "SW2 = 1\n\r" ) : serial .printf ( "SW2 = 0\n\r" );
yabool2001 1:db05ea2d0fe7 50 ( sw3 ) ? serial .printf ( "SW3 = 1\n\r" ) : serial .printf ( "SW3 = 0\n\r" );
yabool2001 1:db05ea2d0fe7 51
yabool2001 1:db05ea2d0fe7 52 serial.printf ( "Pulse status:\n\r" );
yabool2001 1:db05ea2d0fe7 53 ( pulse ) ? serial .printf ( "pulse = 1\n\r" ) : serial .printf ( "pulse = 0\n\r" );
yabool2001 1:db05ea2d0fe7 54 ( pulse_safe ) ? serial .printf ( "pulse_safe = 1\n\r" ) : serial .printf ( "pulse_safe = 0\n\r" );
yabool2001 1:db05ea2d0fe7 55 ( flow_dir ) ? serial .printf ( "flow_dir = 1\n\r" ) : serial .printf ( "flow_dir = 0\n\r" );
yabool2001 0:9dffac13db39 56 }
yabool2001 0:9dffac13db39 57 }