netemera prs

Dependencies:   mbed

Revision:
1:db05ea2d0fe7
Parent:
0:9dffac13db39
Child:
2:9342176884e3
--- a/main.cpp	Tue Mar 26 08:18:20 2019 +0000
+++ b/main.cpp	Tue Mar 26 10:01:53 2019 +0000
@@ -1,59 +1,57 @@
 #include "mbed.h"
 
-Serial serial ( PA_9 , PA_3 );
+Serial serial ( PA_9 , NC );
 
 DigitalOut led_blue ( PA_5 );
 DigitalOut led_red ( PA_8 );
 DigitalOut led_orange ( PA_10 );
 
-InterruptIn int_pa_0 ( PA_0 );
 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 );
-DigitalIn sel ( PA_3 );
 
+InterruptIn int_pa_0 ( PA_0 );
 
 // Toggle LED
 void toggle_led ()
 {
-    wait (0.1); //stan musi być utrzymany przez min. 0.1s
-    if ( pulse == 1 )
-        led_blue = !led_blue;
-    if ( pulse_safe == 1 )
-        led_red = !led_red;
-    if ( flow_dir == 1 )
-        led_orange = !led_orange;
+    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() {
 
-    led_blue = 1;
-    led_red = 1;
-    led_orange = 1;
+    //DIP switch pin set the mode to Pull Up
+    sw1 .mode (PullUp);
+    sw2 .mode (PullUp);
+    sw3 .mode (PullUp);
 
-    // Change LEDs blinking frequency when button is pressed
-    int_pa_0.fall( &toggle_led );
+    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" );
-        if ( sw1 )
-            serial.printf ( "SW1 = 1\n\r" );
-        else
-            serial.printf ( "SW1 = 0\n\r" );
-        if ( sw2 )
-            serial.printf ( "SW2 = 1\n\r" );
-        else
-            serial.printf ( "SW2 = 0\n\r" );
-        if ( sw3 )
-            serial.printf ( "SW3 = 1\n\r" );
-        else
-            serial.printf ( "SW3 = 0\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" );
     }
 }