Test optical sensors and encoder in Recycling module

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
andjoh
Date:
Fri Nov 30 10:25:52 2018 +0000
Commit message:
Test FW to test the optical sensors in Recycling module; ; The color of the LED shows what state the sensors are in.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Nov 30 10:25:52 2018 +0000
@@ -0,0 +1,54 @@
+#include "mbed.h"
+
+DigitalOut LED_GREEN(PA_12);
+DigitalOut LED_RED(PD_2);
+DigitalOut LED_ENABLE(PC_7);
+
+
+DigitalIn TRACK_TOP(PA_6);
+DigitalIn TRACK_BOTTOM(PA_4);
+
+uint32_t blinkTime_ms = 0;
+Timer t;
+
+void green_blink(void){
+    if(t.read_ms() - blinkTime_ms > 200){
+        LED_RED = 0;
+        LED_GREEN = !LED_GREEN;
+        blinkTime_ms = t.read_ms();
+    }
+}
+void red_blink(void){
+    if(t.read_ms() - blinkTime_ms > 200){
+        LED_GREEN = 0;
+        LED_RED = !LED_RED;
+        blinkTime_ms = t.read_ms();
+    }
+}
+
+
+int main() {
+    LED_ENABLE = 1; //turning leds on
+    t.start();
+    blinkTime_ms = t.read_ms();
+    
+    
+    while(1) {
+        
+        if(TRACK_TOP == 0 && TRACK_BOTTOM == 0){    //OM TOMT I SEDELPATH BLINKAR DET GRÖNT
+            green_blink();
+        }else if(TRACK_TOP == 1 && TRACK_BOTTOM == 0){       //OM ÖVRE SENSORN I SEDELPATH ÄR TÄCKT LYSER DET RÖTT
+            LED_RED = 1;
+            LED_GREEN = 0;
+        }else if(TRACK_TOP == 0 && TRACK_BOTTOM == 1){       //OM UNDRE SENSORN I SEDELPATH ÄR TÄCKT LYSER DET GRÖNT
+            LED_RED = 0;
+            LED_GREEN = 1;
+        }else{                      //OM BÅDA SENSORERNA I SEDELPATH ÄR TÄCKTA BLINKAR DET RÖTT
+            red_blink();
+        }
+        
+
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Nov 30 10:25:52 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file