Code for a quadrapod robot.

Dependencies:   ArthropodIK MMA8451Q MODSERIAL TSI TextLCD mbed-rtos mbed PolyServo

Revision:
0:838403674a8f
Child:
2:1f7ee9f3276b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 19 06:11:18 2015 +0000
@@ -0,0 +1,61 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "MODSERIAL.h"
+
+#include "quadrapod_defs.h" //Includes pins and stuff
+
+/**************************************************************************
+              This is the Quadrupod control software.  
+***************************************************************************/
+
+
+MODSERIAL serial(USBTX, USBRX);
+
+DigitalOut led_green(LED_GREEN);
+DigitalOut led_red(LED_RED);
+PwmOut led_blue(LED_BLUE);
+
+void led_fade_thread(void const *args) {
+  // Note that this function doesn't terminate, which is fine since it runs in
+  // a thread.
+  while (1) {
+    // Since the internal LED is active low, inert the duty cycle.
+    led_blue.write(1 - 0);
+    Thread::wait(250);
+    led_blue.write(1 - 0.25);
+    Thread::wait(250);
+    led_blue.write(1 - 0.5);
+    Thread::wait(250);
+    led_blue.write(1 - 0.75);
+    Thread::wait(250);
+  }
+}
+
+void led_blink_periodic(void const *args) {
+  // Toggle the red LED when this function is called.
+  led_red = !led_red;
+}
+
+int main() {
+  // It's always nice to know what version is deployed.
+  serial.printf("Built " __DATE__ " " __TIME__ "\r\n");
+  
+  // Quick blink on startup.
+  led_green = 0;  // Note that the internal LED is active low.
+  wait(0.25);
+  led_green = 1;
+  wait(0.25);
+  
+  // Mandatory "Hello, world!".
+  serial.printf("Hello, world!\r\n");
+
+  // Start a thread running led_fade_thread().
+  Thread ledFadeThread(led_fade_thread);
+  
+  // Set a timer to periodically call led_blink_periodic().
+  RtosTimer ledBlinkTimer(led_blink_periodic);
+  ledBlinkTimer.start(1000);
+
+  // Work is done in the threads, so main() can sleep.
+  Thread::wait(osWaitForever);
+}
\ No newline at end of file