Local copy

Dependencies:   C12832_lcd ConfigFile EthernetInterface LM75B MMA7660 MQTTPacket mbed-rtos mbed

Fork of IBMIoTClientExampleForLPC1768 by Sam Danbury

Revision:
0:6276e9f72327
Child:
1:dd948ce80918
Child:
2:25ddff75a8c7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main.cpp	Mon Jun 23 13:37:46 2014 +0000
@@ -0,0 +1,129 @@
+/*******************************************************************************
+* Copyright (c) 2014 IBM Corporation and other Contributors.
+*
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors: Sam Danbury
+* IBM - Initial Contribution
+*******************************************************************************/
+
+#include "stdio.h"
+#include "mbed.h"
+#include "rtos.h"
+#include "EthernetInterface.h"
+#include "C12832_lcd.h"
+#include "LM75B.h"
+#include "MMA7660.h"
+#include "C12832_lcd.h"
+#include "QuickstartClient.h"
+#include "QuickstartMessage.h"
+
+#include <string>
+
+using namespace std;
+
+//LCD
+C12832_LCD lcd;
+
+//LED
+DigitalOut led1(LED1);
+
+//Accelerometer
+MMA7660 MMA(p28, p27);
+
+//Temperature sensor
+LM75B tmp(p28, p27);
+
+//Joystick
+BusIn Down(p12);
+BusIn Left(p13);
+BusOut Click(p14);
+BusIn Up(p15);
+BusIn Right(p16);
+string joystickPos;
+void joystickThread(void const *args);
+
+//Potentiometer
+AnalogIn ain1(p19);
+AnalogIn ain2(p20);
+float pot1;
+float pot2;
+
+int main()
+{
+    //Connect to the network
+    EthernetInterface eth;
+    eth.init();
+    eth.connect();
+    
+    //Obtain mac address of mbed
+    string mac = eth.getMACAddress();
+    
+    //Remove colons from mac address
+    mac.erase(remove(mac.begin(), mac.end(), ':'), mac.end());
+    
+    //Start thread to read data from joystick
+    Thread jThd(joystickThread);
+    joystickPos = "CENTRE";
+    
+    QuickstartClient* c = new QuickstartClient(mac);
+    
+    while(1) 
+    {
+        //Initialize lcd
+        lcd.cls();
+        lcd.locate(0,0);
+        
+        lcd.printf("Mac address: %s\n", mac);
+        
+        //Flash led to show message has been sent successfully
+        led1 = 1;
+        
+        //Construct quickstart message with desired datapoints
+        QuickstartMessage* m = new QuickstartMessage();
+        m->add("accelX", MMA.x());
+        m->add("accelY", MMA.y());
+        m->add("accelZ", MMA.z());
+        m->add("temp", tmp.read());
+        m->add("joystick", joystickPos);
+        
+        pot1 = ain1;
+        pot2 = ain2;
+        m->add("potentiometer1", pot1);
+        m->add("potentiometer2", pot2);
+        
+        //Message is converted from datapoints into json format and then published
+        c->publish(m->convertToJson());
+        
+        if (m) {
+            delete m;
+        }
+        
+        led1 = 0;
+        
+        //Message published every second
+        wait(1);
+    }
+    
+    eth.disconnect();
+}
+
+void joystickThread(void const *args) {
+    while (1) {
+        if (Down)
+            joystickPos = "DOWN";
+        else if (Left)
+            joystickPos = "LEFT";
+        else if (Click)
+            joystickPos = "CLICK";
+        else if (Up)
+            joystickPos = "UP";
+        else if (Right)
+            joystickPos = "RIGHT";
+        else
+            joystickPos = "CENTRE";
+    }
+}
\ No newline at end of file