RoboCup Base Station
Dependencies: mbed mbed-rtos Wireless Drivers
main.cpp@1:e5373c63f642, 2014-12-31 (annotated)
- Committer:
- jjones646
- Date:
- Wed Dec 31 03:33:35 2014 +0000
- Revision:
- 1:e5373c63f642
- Parent:
- 0:a606cf2249ad
- Child:
- 2:7fd95eae5731
updating with secondary radio status led support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jjones646 | 0:a606cf2249ad | 1 | // Cycle through a 7-segment LCD display |
jjones646 | 0:a606cf2249ad | 2 | |
jjones646 | 0:a606cf2249ad | 3 | #include "mbed.h" |
jjones646 | 0:a606cf2249ad | 4 | |
jjones646 | 0:a606cf2249ad | 5 | // Outputs used as input values to the 7-segment binary decoder |
jjones646 | 0:a606cf2249ad | 6 | DigitalOut signal[4] = {p17, p18, p19, p20}; |
jjones646 | 0:a606cf2249ad | 7 | |
jjones646 | 0:a606cf2249ad | 8 | // For latching the 7 segment led's output |
jjones646 | 0:a606cf2249ad | 9 | DigitalOut latch(p16); |
jjones646 | 0:a606cf2249ad | 10 | |
jjones646 | 0:a606cf2249ad | 11 | // To show that the mbed is running |
jjones646 | 0:a606cf2249ad | 12 | DigitalOut status_led(LED1); |
jjones646 | 0:a606cf2249ad | 13 | |
jjones646 | 1:e5373c63f642 | 14 | DigitalOut r2_led[3] = {p24, p25, p26}; // TX, RX, ERR |
jjones646 | 1:e5373c63f642 | 15 | |
jjones646 | 0:a606cf2249ad | 16 | // Function for writing a number to the 7-segment display |
jjones646 | 0:a606cf2249ad | 17 | void writeSegment(uint8_t val) |
jjones646 | 0:a606cf2249ad | 18 | { |
jjones646 | 0:a606cf2249ad | 19 | // write out the new value |
jjones646 | 0:a606cf2249ad | 20 | for (int i=0; i<4; i++) |
jjones646 | 0:a606cf2249ad | 21 | signal[i] = ((1<<i) & (val)) & 0x0F; |
jjones646 | 0:a606cf2249ad | 22 | |
jjones646 | 0:a606cf2249ad | 23 | // latch the value |
jjones646 | 0:a606cf2249ad | 24 | for (int i=0; i<2; i++) |
jjones646 | 0:a606cf2249ad | 25 | latch = !latch; |
jjones646 | 0:a606cf2249ad | 26 | } |
jjones646 | 0:a606cf2249ad | 27 | |
jjones646 | 0:a606cf2249ad | 28 | int main() |
jjones646 | 0:a606cf2249ad | 29 | { |
jjones646 | 1:e5373c63f642 | 30 | // turn all LEDs off initially |
jjones646 | 1:e5373c63f642 | 31 | for (int i=0; i<3; i++) |
jjones646 | 1:e5373c63f642 | 32 | r2_led[i] = 1; |
jjones646 | 1:e5373c63f642 | 33 | |
jjones646 | 0:a606cf2249ad | 34 | latch = 0; // initialize the latch pin for the CD4511B decoder |
jjones646 | 0:a606cf2249ad | 35 | status_led = 0; // initialize & turn off led for startup operations |
jjones646 | 0:a606cf2249ad | 36 | |
jjones646 | 0:a606cf2249ad | 37 | uint8_t channel; // limit to 4 bits (0x00 to 0x0F) |
jjones646 | 0:a606cf2249ad | 38 | channel = 8; // light up all of the 7-segment's segments at startup - allows for the user to detect if there's a problem |
jjones646 | 0:a606cf2249ad | 39 | writeSegment(channel); |
jjones646 | 1:e5373c63f642 | 40 | channel = 0; // start back over at 0 |
jjones646 | 1:e5373c63f642 | 41 | |
jjones646 | 1:e5373c63f642 | 42 | wait(0.2); |
jjones646 | 0:a606cf2249ad | 43 | |
jjones646 | 1:e5373c63f642 | 44 | // turn on all secondary radio status LEDs |
jjones646 | 1:e5373c63f642 | 45 | for (int i=2; i>=0; i--) { |
jjones646 | 1:e5373c63f642 | 46 | r2_led[i] = 0; |
jjones646 | 1:e5373c63f642 | 47 | wait(0.2); |
jjones646 | 1:e5373c63f642 | 48 | } |
jjones646 | 1:e5373c63f642 | 49 | |
jjones646 | 1:e5373c63f642 | 50 | // hold |
jjones646 | 1:e5373c63f642 | 51 | wait(0.3); |
jjones646 | 1:e5373c63f642 | 52 | |
jjones646 | 1:e5373c63f642 | 53 | // turn off all secondary radio status LEDs |
jjones646 | 1:e5373c63f642 | 54 | for (int i=0; i<3; i++) { |
jjones646 | 1:e5373c63f642 | 55 | r2_led[i] = 1; |
jjones646 | 1:e5373c63f642 | 56 | wait(0.2); |
jjones646 | 1:e5373c63f642 | 57 | } |
jjones646 | 0:a606cf2249ad | 58 | |
jjones646 | 0:a606cf2249ad | 59 | while(1) { |
jjones646 | 0:a606cf2249ad | 60 | // send numerical value to 7-segment & hold for a while |
jjones646 | 0:a606cf2249ad | 61 | writeSegment(channel++); |
jjones646 | 0:a606cf2249ad | 62 | wait(0.3); |
jjones646 | 0:a606cf2249ad | 63 | status_led = !status_led; |
jjones646 | 1:e5373c63f642 | 64 | |
jjones646 | 0:a606cf2249ad | 65 | // wait again just so that the status led and segment are out of sync |
jjones646 | 0:a606cf2249ad | 66 | wait(0.2); |
jjones646 | 1:e5373c63f642 | 67 | |
jjones646 | 0:a606cf2249ad | 68 | // reset value if too high |
jjones646 | 0:a606cf2249ad | 69 | channel = channel > 9 ? 0 : channel; |
jjones646 | 0:a606cf2249ad | 70 | } |
jjones646 | 0:a606cf2249ad | 71 | } |