LE KICKASS TEAM / Mbed 2 deprecated RTOS_Lights_Master

Dependencies:   mbed-rtos mbed

Revision:
1:0a93e9e88ad3
Parent:
0:4555c427d7a8
Child:
2:f3ae10decc2f
--- a/main.cpp	Wed Oct 07 20:28:50 2015 +0000
+++ b/main.cpp	Wed Dec 02 23:11:31 2015 +0000
@@ -1,10 +1,6 @@
 #include "mbed.h"
-#include "LM75B.h"
+#include "rtos.h"
 #include "MMA7455.h"
-#include "EthernetInterface.h"
-
-#define F 0
-#define C 1
 
 // thresholds for detecting a rotation of 90 deg or more
 #define X_TH 60
@@ -24,9 +20,13 @@
     Utility Functions
 **************************
 */
-float tempConverter(float inTemp, bool convDir);
+void SerialInit();
+void AccInit();
+void LEDsInit();
 void accFeed();
 void sampleAcc(int period, int32_t data[3]);
+void LEDPush(void);
+void LEDS(void const *args);
 
 /*
 **************************
@@ -35,9 +35,6 @@
 */
 const char banner[37] = "Serial Comm Established with LPC4088";
 
-// holds last temperature reading
-float currTemp = 0;
-
 // x, y, z
 // holds current position
 int32_t accPos[3]           = {};
@@ -45,6 +42,8 @@
 int32_t accData[20][20][20] = {};
 // holds calibration offsets
 int32_t accCal[3]           = {};
+// a counter for LED animations
+uint8_t LEDvals = 0;
 
 /*
 **************************
@@ -55,10 +54,10 @@
 Serial terminal(USBTX, USBRX);
 // accelerometer on I2C bus
 MMA7455 acc(P0_27, P0_28);
-// temperature sensor on I2C bus
-LM75B temp(P0_27, P0_28, LM75B::ADDRESS_1, 120);
-// ethernet connection to log sensor data on a server
-EthernetInterface eth;
+// SPI interface for 8 LEDs
+SPI leds(p5, NC, p7);
+// load for shift register
+DigitalOut ld(p30);
 
 int main() {
     /*
@@ -67,29 +66,22 @@
     **************************
     */
     SerialInit();
-    EthernetInit();
-    TempInit();
     AccInit();
+    
+    LEDsInit();
+    
+    RtosTimer refresh_timer(LEDS, osTimerPeriodic, (void *)0);
+    refresh_timer.start(60);
+    
+    terminal.printf("Timer started.");    
     /*
     **************************
           Main Execution
     **************************
     */
     while(1) {
-        currTemp = (float)temp;
-        terminal.printf("Current temperature (F): %.1f", tempConverter(currTemp, F));
-        newline();
-        
         acc.read(accPos[0], accPos[1], accPos[2]);
-        while(accPos[2] < Z_TH) {
-            // output audible beep
-            //alarm = 1;
-            terminal.printf("BEEEEEP!");
-            newline();
-            acc.read(accPos[0], accPos[1], accPos[2]);
-        }
-        wait(1);
-        //alarm = 0;    
+        LEDvals = (accPos[2]%4);   
     }
 }
 
@@ -106,42 +98,6 @@
     newline();
 }
 
-void EthernetInit()
-{
-    // initialize ethernet connection
-    terminal.printf("Establishing ethernet connection...");
-    newline();
-    // use DHCP - static IP
-    eth.init("192.168.1.4","255.255.255.0","192.168.1.1"); 
-    eth.connect();
-    terminal.printf("  IP Address: %s", eth.getIPAddress()); newline();
-    TCPSocketConnection socket;
-    socket.connect("192.168.1.3", 1001);
-    if(socket.is_connected()) {
-        terminal.printf("  Connected!");
-        // write to server
-        char http_cmd[] = "This is a test";  
-        socket.send_all(http_cmd, sizeof(http_cmd)-1);
-    }
-    else
-        terminal.printf("  Unable to connect.");
-    newline(); newline();
-}
-
-void TempInit()
-{
-    terminal.printf("Temperature sensor...");
-    // verify connection with temp sensor
-    if(temp.open()) {
-        terminal.printf("initialized.");
-        newline();
-    }
-    else {
-        terminal.printf("unavailable.");
-        newline();
-    }
-}
-
 void AccInit()
 {
     // configure accelerometer for 2G range
@@ -193,22 +149,6 @@
         terminal.putc('*');    
 }
 
-// converts a temperature reading from C > F or F > C
-// convDir = 0: F > C  
-// convDir = 1: C > F
-float tempConverter(float inTemp, bool convDir)
-{
-    const float CToF = (9.0/5.0);
-    const float FToC = (5.0/9.0);
-    const int offset = 32;
-    if(convDir == 0){ //Convert C to F
-        return (inTemp * CToF) + offset;
-    }
-    else{ //Convert F to C
-        return (inTemp - offset) * FToC;
-    }       
-}
-
 // prints the current positional data from the accelerometer
 void accFeed()
 {
@@ -243,4 +183,42 @@
         for(int i = period*4; i < 20; i++)
             accData[i][i][i] = 0;
     }
+}
+
+void LEDS(void const *args) 
+{
+    LEDPush();
+}
+
+void LEDsInit()
+{
+    terminal.printf("Setting format...");
+    newline();
+    leds.format(8, 3);
+    leds.frequency(100000);
+    terminal.printf("Creating timer...");
+    newline();
+    ld = 1;
+    LEDvals = 0x00;
+    LEDPush();
+    LEDvals = 0xFF;
+    terminal.printf("LEDvals = %d", LEDvals);
+    newline();
+    /*LEDvals = 0xAA;
+    LEDPush();
+    wait(1);
+    LEDvals = 0x55;
+    LEDPush();*/
+    terminal.printf("Starting timer...");
+    newline();
+    terminal.printf("Timer started.");
+}
+
+void LEDPush(void)
+{
+    ld = 0;
+    leds.write(LEDvals);
+    ld = 1;
+    terminal.printf("LEDvals = %d", LEDvals);
+    newline();
 }
\ No newline at end of file