Test optical sensors and encoder in Recycling module
Dependencies: mbed
main.cpp@0:d7346061a5eb, 2018-11-30 (annotated)
- Committer:
- andjoh
- Date:
- Fri Nov 30 10:25:52 2018 +0000
- Revision:
- 0:d7346061a5eb
Test FW to test the optical sensors in Recycling module; ; The color of the LED shows what state the sensors are in.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andjoh | 0:d7346061a5eb | 1 | #include "mbed.h" |
andjoh | 0:d7346061a5eb | 2 | |
andjoh | 0:d7346061a5eb | 3 | DigitalOut LED_GREEN(PA_12); |
andjoh | 0:d7346061a5eb | 4 | DigitalOut LED_RED(PD_2); |
andjoh | 0:d7346061a5eb | 5 | DigitalOut LED_ENABLE(PC_7); |
andjoh | 0:d7346061a5eb | 6 | |
andjoh | 0:d7346061a5eb | 7 | |
andjoh | 0:d7346061a5eb | 8 | DigitalIn TRACK_TOP(PA_6); |
andjoh | 0:d7346061a5eb | 9 | DigitalIn TRACK_BOTTOM(PA_4); |
andjoh | 0:d7346061a5eb | 10 | |
andjoh | 0:d7346061a5eb | 11 | uint32_t blinkTime_ms = 0; |
andjoh | 0:d7346061a5eb | 12 | Timer t; |
andjoh | 0:d7346061a5eb | 13 | |
andjoh | 0:d7346061a5eb | 14 | void green_blink(void){ |
andjoh | 0:d7346061a5eb | 15 | if(t.read_ms() - blinkTime_ms > 200){ |
andjoh | 0:d7346061a5eb | 16 | LED_RED = 0; |
andjoh | 0:d7346061a5eb | 17 | LED_GREEN = !LED_GREEN; |
andjoh | 0:d7346061a5eb | 18 | blinkTime_ms = t.read_ms(); |
andjoh | 0:d7346061a5eb | 19 | } |
andjoh | 0:d7346061a5eb | 20 | } |
andjoh | 0:d7346061a5eb | 21 | void red_blink(void){ |
andjoh | 0:d7346061a5eb | 22 | if(t.read_ms() - blinkTime_ms > 200){ |
andjoh | 0:d7346061a5eb | 23 | LED_GREEN = 0; |
andjoh | 0:d7346061a5eb | 24 | LED_RED = !LED_RED; |
andjoh | 0:d7346061a5eb | 25 | blinkTime_ms = t.read_ms(); |
andjoh | 0:d7346061a5eb | 26 | } |
andjoh | 0:d7346061a5eb | 27 | } |
andjoh | 0:d7346061a5eb | 28 | |
andjoh | 0:d7346061a5eb | 29 | |
andjoh | 0:d7346061a5eb | 30 | int main() { |
andjoh | 0:d7346061a5eb | 31 | LED_ENABLE = 1; //turning leds on |
andjoh | 0:d7346061a5eb | 32 | t.start(); |
andjoh | 0:d7346061a5eb | 33 | blinkTime_ms = t.read_ms(); |
andjoh | 0:d7346061a5eb | 34 | |
andjoh | 0:d7346061a5eb | 35 | |
andjoh | 0:d7346061a5eb | 36 | while(1) { |
andjoh | 0:d7346061a5eb | 37 | |
andjoh | 0:d7346061a5eb | 38 | if(TRACK_TOP == 0 && TRACK_BOTTOM == 0){ //OM TOMT I SEDELPATH BLINKAR DET GRÖNT |
andjoh | 0:d7346061a5eb | 39 | green_blink(); |
andjoh | 0:d7346061a5eb | 40 | }else if(TRACK_TOP == 1 && TRACK_BOTTOM == 0){ //OM ÖVRE SENSORN I SEDELPATH ÄR TÄCKT LYSER DET RÖTT |
andjoh | 0:d7346061a5eb | 41 | LED_RED = 1; |
andjoh | 0:d7346061a5eb | 42 | LED_GREEN = 0; |
andjoh | 0:d7346061a5eb | 43 | }else if(TRACK_TOP == 0 && TRACK_BOTTOM == 1){ //OM UNDRE SENSORN I SEDELPATH ÄR TÄCKT LYSER DET GRÖNT |
andjoh | 0:d7346061a5eb | 44 | LED_RED = 0; |
andjoh | 0:d7346061a5eb | 45 | LED_GREEN = 1; |
andjoh | 0:d7346061a5eb | 46 | }else{ //OM BÅDA SENSORERNA I SEDELPATH ÄR TÄCKTA BLINKAR DET RÖTT |
andjoh | 0:d7346061a5eb | 47 | red_blink(); |
andjoh | 0:d7346061a5eb | 48 | } |
andjoh | 0:d7346061a5eb | 49 | |
andjoh | 0:d7346061a5eb | 50 | |
andjoh | 0:d7346061a5eb | 51 | } |
andjoh | 0:d7346061a5eb | 52 | } |
andjoh | 0:d7346061a5eb | 53 | |
andjoh | 0:d7346061a5eb | 54 |