New quadrupod variant
Dependencies: ArthropodIK MMA8451Q MODSERIAL TSI TextLCD mbed-rtos mbed
Fork of Quadrapod by
main.cpp@0:838403674a8f, 2015-06-19 (annotated)
- Committer:
- ikrase
- Date:
- Fri Jun 19 06:11:18 2015 +0000
- Revision:
- 0:838403674a8f
- Child:
- 2:1f7ee9f3276b
The beginning. Rough, raw templates.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ikrase | 0:838403674a8f | 1 | #include "mbed.h" |
ikrase | 0:838403674a8f | 2 | #include "rtos.h" |
ikrase | 0:838403674a8f | 3 | #include "MODSERIAL.h" |
ikrase | 0:838403674a8f | 4 | |
ikrase | 0:838403674a8f | 5 | #include "quadrapod_defs.h" //Includes pins and stuff |
ikrase | 0:838403674a8f | 6 | |
ikrase | 0:838403674a8f | 7 | /************************************************************************** |
ikrase | 0:838403674a8f | 8 | This is the Quadrupod control software. |
ikrase | 0:838403674a8f | 9 | ***************************************************************************/ |
ikrase | 0:838403674a8f | 10 | |
ikrase | 0:838403674a8f | 11 | |
ikrase | 0:838403674a8f | 12 | MODSERIAL serial(USBTX, USBRX); |
ikrase | 0:838403674a8f | 13 | |
ikrase | 0:838403674a8f | 14 | DigitalOut led_green(LED_GREEN); |
ikrase | 0:838403674a8f | 15 | DigitalOut led_red(LED_RED); |
ikrase | 0:838403674a8f | 16 | PwmOut led_blue(LED_BLUE); |
ikrase | 0:838403674a8f | 17 | |
ikrase | 0:838403674a8f | 18 | void led_fade_thread(void const *args) { |
ikrase | 0:838403674a8f | 19 | // Note that this function doesn't terminate, which is fine since it runs in |
ikrase | 0:838403674a8f | 20 | // a thread. |
ikrase | 0:838403674a8f | 21 | while (1) { |
ikrase | 0:838403674a8f | 22 | // Since the internal LED is active low, inert the duty cycle. |
ikrase | 0:838403674a8f | 23 | led_blue.write(1 - 0); |
ikrase | 0:838403674a8f | 24 | Thread::wait(250); |
ikrase | 0:838403674a8f | 25 | led_blue.write(1 - 0.25); |
ikrase | 0:838403674a8f | 26 | Thread::wait(250); |
ikrase | 0:838403674a8f | 27 | led_blue.write(1 - 0.5); |
ikrase | 0:838403674a8f | 28 | Thread::wait(250); |
ikrase | 0:838403674a8f | 29 | led_blue.write(1 - 0.75); |
ikrase | 0:838403674a8f | 30 | Thread::wait(250); |
ikrase | 0:838403674a8f | 31 | } |
ikrase | 0:838403674a8f | 32 | } |
ikrase | 0:838403674a8f | 33 | |
ikrase | 0:838403674a8f | 34 | void led_blink_periodic(void const *args) { |
ikrase | 0:838403674a8f | 35 | // Toggle the red LED when this function is called. |
ikrase | 0:838403674a8f | 36 | led_red = !led_red; |
ikrase | 0:838403674a8f | 37 | } |
ikrase | 0:838403674a8f | 38 | |
ikrase | 0:838403674a8f | 39 | int main() { |
ikrase | 0:838403674a8f | 40 | // It's always nice to know what version is deployed. |
ikrase | 0:838403674a8f | 41 | serial.printf("Built " __DATE__ " " __TIME__ "\r\n"); |
ikrase | 0:838403674a8f | 42 | |
ikrase | 0:838403674a8f | 43 | // Quick blink on startup. |
ikrase | 0:838403674a8f | 44 | led_green = 0; // Note that the internal LED is active low. |
ikrase | 0:838403674a8f | 45 | wait(0.25); |
ikrase | 0:838403674a8f | 46 | led_green = 1; |
ikrase | 0:838403674a8f | 47 | wait(0.25); |
ikrase | 0:838403674a8f | 48 | |
ikrase | 0:838403674a8f | 49 | // Mandatory "Hello, world!". |
ikrase | 0:838403674a8f | 50 | serial.printf("Hello, world!\r\n"); |
ikrase | 0:838403674a8f | 51 | |
ikrase | 0:838403674a8f | 52 | // Start a thread running led_fade_thread(). |
ikrase | 0:838403674a8f | 53 | Thread ledFadeThread(led_fade_thread); |
ikrase | 0:838403674a8f | 54 | |
ikrase | 0:838403674a8f | 55 | // Set a timer to periodically call led_blink_periodic(). |
ikrase | 0:838403674a8f | 56 | RtosTimer ledBlinkTimer(led_blink_periodic); |
ikrase | 0:838403674a8f | 57 | ledBlinkTimer.start(1000); |
ikrase | 0:838403674a8f | 58 | |
ikrase | 0:838403674a8f | 59 | // Work is done in the threads, so main() can sleep. |
ikrase | 0:838403674a8f | 60 | Thread::wait(osWaitForever); |
ikrase | 0:838403674a8f | 61 | } |