![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
RoboCup Base Station
Dependencies: mbed mbed-rtos Wireless Drivers
main.cpp@2:7fd95eae5731, 2014-12-31 (annotated)
- Committer:
- jjones646
- Date:
- Wed Dec 31 09:17:06 2014 +0000
- Revision:
- 2:7fd95eae5731
- Parent:
- 1:e5373c63f642
- Child:
- 3:c3114df544e8
updating startup routine
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jjones646 | 2:7fd95eae5731 | 1 | // RoboCup dual-frequency band base station |
jjones646 | 0:a606cf2249ad | 2 | |
jjones646 | 2:7fd95eae5731 | 3 | #include "BaseStation.h" |
jjones646 | 1:e5373c63f642 | 4 | |
jjones646 | 0:a606cf2249ad | 5 | // Function for writing a number to the 7-segment display |
jjones646 | 2:7fd95eae5731 | 6 | void writeSegment(uint8_t val, DigitalOut& latch) |
jjones646 | 0:a606cf2249ad | 7 | { |
jjones646 | 2:7fd95eae5731 | 8 | // Outputs used as input values to the 7-segment binary decoder - uses latching inputs |
jjones646 | 2:7fd95eae5731 | 9 | DigitalOut signal[4] = { RJ_7_SEG_PINS }; |
jjones646 | 2:7fd95eae5731 | 10 | |
jjones646 | 0:a606cf2249ad | 11 | // write out the new value |
jjones646 | 0:a606cf2249ad | 12 | for (int i=0; i<4; i++) |
jjones646 | 0:a606cf2249ad | 13 | signal[i] = ((1<<i) & (val)) & 0x0F; |
jjones646 | 0:a606cf2249ad | 14 | |
jjones646 | 0:a606cf2249ad | 15 | // latch the value |
jjones646 | 0:a606cf2249ad | 16 | for (int i=0; i<2; i++) |
jjones646 | 0:a606cf2249ad | 17 | latch = !latch; |
jjones646 | 0:a606cf2249ad | 18 | } |
jjones646 | 0:a606cf2249ad | 19 | |
jjones646 | 2:7fd95eae5731 | 20 | void seg_task(void const *arg) |
jjones646 | 2:7fd95eae5731 | 21 | { |
jjones646 | 2:7fd95eae5731 | 22 | // latch pin for 7-seg |
jjones646 | 2:7fd95eae5731 | 23 | DigitalOut latch( RJ_7_SEG_LATCH_PIN, 0 ); |
jjones646 | 2:7fd95eae5731 | 24 | |
jjones646 | 2:7fd95eae5731 | 25 | // Decimal point initialized to OFF |
jjones646 | 2:7fd95eae5731 | 26 | DigitalOut decimal( RJ_7_SEG_DOT_PIN, 1 ); |
jjones646 | 2:7fd95eae5731 | 27 | |
jjones646 | 2:7fd95eae5731 | 28 | uint8_t channel = 8; |
jjones646 | 2:7fd95eae5731 | 29 | writeSegment(channel, latch); |
jjones646 | 2:7fd95eae5731 | 30 | channel = 0; // start from 0 once the main task's look begins |
jjones646 | 2:7fd95eae5731 | 31 | |
jjones646 | 2:7fd95eae5731 | 32 | // wait to be signaled before beginning |
jjones646 | 2:7fd95eae5731 | 33 | osSignalWait(0x01, osWaitForever); |
jjones646 | 2:7fd95eae5731 | 34 | |
jjones646 | 2:7fd95eae5731 | 35 | // give a small delay to ensure the startup value stays lit for some time |
jjones646 | 2:7fd95eae5731 | 36 | Thread::wait(500); |
jjones646 | 2:7fd95eae5731 | 37 | |
jjones646 | 2:7fd95eae5731 | 38 | // turn the decimal point off |
jjones646 | 2:7fd95eae5731 | 39 | decimal = 0; |
jjones646 | 2:7fd95eae5731 | 40 | |
jjones646 | 2:7fd95eae5731 | 41 | while(1) { // loop forever |
jjones646 | 2:7fd95eae5731 | 42 | // send numerical value to 7-segment & hold for a while |
jjones646 | 2:7fd95eae5731 | 43 | writeSegment(channel++, latch); |
jjones646 | 2:7fd95eae5731 | 44 | channel = (channel > 9) ? 0 : channel; // reset value if too high |
jjones646 | 2:7fd95eae5731 | 45 | Thread::wait(1000); |
jjones646 | 2:7fd95eae5731 | 46 | } |
jjones646 | 2:7fd95eae5731 | 47 | } |
jjones646 | 2:7fd95eae5731 | 48 | |
jjones646 | 0:a606cf2249ad | 49 | int main() |
jjones646 | 0:a606cf2249ad | 50 | { |
jjones646 | 2:7fd95eae5731 | 51 | // RGB Status LED |
jjones646 | 2:7fd95eae5731 | 52 | PwmOut rgb_led[3] = { RJ_RGB_LED_PINS }; |
jjones646 | 1:e5373c63f642 | 53 | |
jjones646 | 2:7fd95eae5731 | 54 | // Primary radio status LEDs |
jjones646 | 2:7fd95eae5731 | 55 | DigitalOut r1_led[3] = { RJ_PRIMARY_RADIO_LEDS }; |
jjones646 | 2:7fd95eae5731 | 56 | |
jjones646 | 2:7fd95eae5731 | 57 | // Secondary radio status LEDs |
jjones646 | 2:7fd95eae5731 | 58 | DigitalOut r2_led[3] = { RJ_SECONDARY_RADIO_LEDS }; |
jjones646 | 0:a606cf2249ad | 59 | |
jjones646 | 2:7fd95eae5731 | 60 | // Used for controlling power to the RGB LED's shared annode lead |
jjones646 | 2:7fd95eae5731 | 61 | DigitalOut rgb_pwr( RJ_RGB_LED_ANNODE, 0 ); |
jjones646 | 2:7fd95eae5731 | 62 | |
jjones646 | 2:7fd95eae5731 | 63 | // Start 7-segment task |
jjones646 | 2:7fd95eae5731 | 64 | Thread thread_seg_task(seg_task); |
jjones646 | 0:a606cf2249ad | 65 | |
jjones646 | 2:7fd95eae5731 | 66 | // turn all LEDs off initially - values are inverted since LEDs are sinking the current |
jjones646 | 2:7fd95eae5731 | 67 | for (int i=0; i<3; i++) { |
jjones646 | 2:7fd95eae5731 | 68 | rgb_led[i] = 1; |
jjones646 | 2:7fd95eae5731 | 69 | r1_led[i] = 1; |
jjones646 | 2:7fd95eae5731 | 70 | r2_led[i] = 1; |
jjones646 | 1:e5373c63f642 | 71 | } |
jjones646 | 1:e5373c63f642 | 72 | |
jjones646 | 2:7fd95eae5731 | 73 | // =========== Cyle primary & secondary radio status LEDs =========== |
jjones646 | 2:7fd95eae5731 | 74 | // turn on all radio status LEDs |
jjones646 | 1:e5373c63f642 | 75 | for (int i=0; i<3; i++) { |
jjones646 | 2:7fd95eae5731 | 76 | r1_led[i] = 0; |
jjones646 | 2:7fd95eae5731 | 77 | r2_led[i] = 0; |
jjones646 | 2:7fd95eae5731 | 78 | Thread::wait(50); |
jjones646 | 2:7fd95eae5731 | 79 | } |
jjones646 | 2:7fd95eae5731 | 80 | // turn off all radio status LEDs |
jjones646 | 2:7fd95eae5731 | 81 | for (int i=0; i<3; i++) { |
jjones646 | 2:7fd95eae5731 | 82 | r1_led[i] = 1; |
jjones646 | 1:e5373c63f642 | 83 | r2_led[i] = 1; |
jjones646 | 2:7fd95eae5731 | 84 | Thread::wait(50); |
jjones646 | 1:e5373c63f642 | 85 | } |
jjones646 | 0:a606cf2249ad | 86 | |
jjones646 | 2:7fd95eae5731 | 87 | // give power to all colors of the RGB LED and turn off decimal point |
jjones646 | 2:7fd95eae5731 | 88 | rgb_pwr = 1; |
jjones646 | 2:7fd95eae5731 | 89 | |
jjones646 | 2:7fd95eae5731 | 90 | // tell the segment thread to begin its task |
jjones646 | 2:7fd95eae5731 | 91 | thread_seg_task.signal_set(0x01); |
jjones646 | 2:7fd95eae5731 | 92 | |
jjones646 | 2:7fd95eae5731 | 93 | // fade the RGB LED up to green and half power |
jjones646 | 2:7fd95eae5731 | 94 | for (float i=1.0; i>0.5; i-=0.01) { |
jjones646 | 2:7fd95eae5731 | 95 | rgb_led[G] = i; |
jjones646 | 2:7fd95eae5731 | 96 | Thread::wait(20); |
jjones646 | 2:7fd95eae5731 | 97 | } |
jjones646 | 1:e5373c63f642 | 98 | |
jjones646 | 2:7fd95eae5731 | 99 | // at led_intensity[3] = { 0, 0, 0 }; |
jjones646 | 2:7fd95eae5731 | 100 | srand(time(NULL)); |
jjones646 | 1:e5373c63f642 | 101 | |
jjones646 | 2:7fd95eae5731 | 102 | // loop forever ==================== |
jjones646 | 2:7fd95eae5731 | 103 | while(1) { |
jjones646 | 2:7fd95eae5731 | 104 | uint8_t color = rand()%2; |
jjones646 | 2:7fd95eae5731 | 105 | |
jjones646 | 2:7fd95eae5731 | 106 | // rgb_led[color] = (rand()%1000)/1000; |
jjones646 | 2:7fd95eae5731 | 107 | |
jjones646 | 2:7fd95eae5731 | 108 | // delay |
jjones646 | 2:7fd95eae5731 | 109 | Thread::wait(300); |
jjones646 | 0:a606cf2249ad | 110 | } |
jjones646 | 0:a606cf2249ad | 111 | } |