![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
RoboCup Base Station
Dependencies: mbed mbed-rtos Wireless Drivers
Diff: main.cpp
- Revision:
- 2:7fd95eae5731
- Parent:
- 1:e5373c63f642
- Child:
- 3:c3114df544e8
--- a/main.cpp Wed Dec 31 03:33:35 2014 +0000 +++ b/main.cpp Wed Dec 31 09:17:06 2014 +0000 @@ -1,21 +1,13 @@ -// Cycle through a 7-segment LCD display - -#include "mbed.h" - -// Outputs used as input values to the 7-segment binary decoder -DigitalOut signal[4] = {p17, p18, p19, p20}; +// RoboCup dual-frequency band base station -// For latching the 7 segment led's output -DigitalOut latch(p16); - -// To show that the mbed is running -DigitalOut status_led(LED1); - -DigitalOut r2_led[3] = {p24, p25, p26}; // TX, RX, ERR +#include "BaseStation.h" // Function for writing a number to the 7-segment display -void writeSegment(uint8_t val) +void writeSegment(uint8_t val, DigitalOut& latch) { + // Outputs used as input values to the 7-segment binary decoder - uses latching inputs + DigitalOut signal[4] = { RJ_7_SEG_PINS }; + // write out the new value for (int i=0; i<4; i++) signal[i] = ((1<<i) & (val)) & 0x0F; @@ -25,47 +17,95 @@ latch = !latch; } +void seg_task(void const *arg) +{ + // latch pin for 7-seg + DigitalOut latch( RJ_7_SEG_LATCH_PIN, 0 ); + + // Decimal point initialized to OFF + DigitalOut decimal( RJ_7_SEG_DOT_PIN, 1 ); + + uint8_t channel = 8; + writeSegment(channel, latch); + channel = 0; // start from 0 once the main task's look begins + + // wait to be signaled before beginning + osSignalWait(0x01, osWaitForever); + + // give a small delay to ensure the startup value stays lit for some time + Thread::wait(500); + + // turn the decimal point off + decimal = 0; + + while(1) { // loop forever + // send numerical value to 7-segment & hold for a while + writeSegment(channel++, latch); + channel = (channel > 9) ? 0 : channel; // reset value if too high + Thread::wait(1000); + } +} + int main() { - // turn all LEDs off initially - for (int i=0; i<3; i++) - r2_led[i] = 1; + // RGB Status LED + PwmOut rgb_led[3] = { RJ_RGB_LED_PINS }; - latch = 0; // initialize the latch pin for the CD4511B decoder - status_led = 0; // initialize & turn off led for startup operations + // Primary radio status LEDs + DigitalOut r1_led[3] = { RJ_PRIMARY_RADIO_LEDS }; + + // Secondary radio status LEDs + DigitalOut r2_led[3] = { RJ_SECONDARY_RADIO_LEDS }; - uint8_t channel; // limit to 4 bits (0x00 to 0x0F) - channel = 8; // light up all of the 7-segment's segments at startup - allows for the user to detect if there's a problem - writeSegment(channel); - channel = 0; // start back over at 0 - - wait(0.2); + // Used for controlling power to the RGB LED's shared annode lead + DigitalOut rgb_pwr( RJ_RGB_LED_ANNODE, 0 ); + + // Start 7-segment task + Thread thread_seg_task(seg_task); - // turn on all secondary radio status LEDs - for (int i=2; i>=0; i--) { - r2_led[i] = 0; - wait(0.2); + // turn all LEDs off initially - values are inverted since LEDs are sinking the current + for (int i=0; i<3; i++) { + rgb_led[i] = 1; + r1_led[i] = 1; + r2_led[i] = 1; } - // hold - wait(0.3); - - // turn off all secondary radio status LEDs + // =========== Cyle primary & secondary radio status LEDs =========== + // turn on all radio status LEDs for (int i=0; i<3; i++) { + r1_led[i] = 0; + r2_led[i] = 0; + Thread::wait(50); + } + // turn off all radio status LEDs + for (int i=0; i<3; i++) { + r1_led[i] = 1; r2_led[i] = 1; - wait(0.2); + Thread::wait(50); } - while(1) { - // send numerical value to 7-segment & hold for a while - writeSegment(channel++); - wait(0.3); - status_led = !status_led; + // give power to all colors of the RGB LED and turn off decimal point + rgb_pwr = 1; + + // tell the segment thread to begin its task + thread_seg_task.signal_set(0x01); + + // fade the RGB LED up to green and half power + for (float i=1.0; i>0.5; i-=0.01) { + rgb_led[G] = i; + Thread::wait(20); + } - // wait again just so that the status led and segment are out of sync - wait(0.2); + // at led_intensity[3] = { 0, 0, 0 }; + srand(time(NULL)); - // reset value if too high - channel = channel > 9 ? 0 : channel; + // loop forever ==================== + while(1) { + uint8_t color = rand()%2; + + // rgb_led[color] = (rand()%1000)/1000; + + // delay + Thread::wait(300); } } \ No newline at end of file