Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832_lcd EthernetInterface SensorDataParser mbed-rtos mbed USBDevice
Fork of SensorStream_BlinkyDemo by
main.cpp
- Committer:
- dan
- Date:
- 2013-10-28
- Revision:
- 0:a3d60f53f22f
- Child:
- 1:50e52569be43
File content as of revision 0:a3d60f53f22f:
#include "mbed.h"
#include "EthernetInterface.h"
#include "C12832_lcd.h"
#include "SensorDataParser.h"
#include <math.h>
static EthernetInterface eth;
static C12832_LCD lcd;
static Serial pc(USBTX, USBRX);
DigitalOut led_left(LED1);
DigitalOut led_up(LED2);
DigitalOut led_down(LED3);
DigitalOut led_right(LED4);
// Configuration
#define SERVER_PORT 5555
#define MAX_BUF_SIZE 512
#define SENSE_DELTA 0.1
static void ethernet_init() {
eth.init();
if(eth.connect(30000) == 0)
pc.printf("Connect OK\n\r");
lcd.locate(0,0);
lcd.printf("IP:%s", eth.getIPAddress());
pc.printf("IP Address: %s\n\r", eth.getIPAddress());
}
static void main_loop() {
UDPSocket server;
Endpoint client;
char buffer[MAX_BUF_SIZE];
SENSOR_DATA pd;
server.bind(SERVER_PORT);
while (true) {
int n = server.receiveFrom(client, buffer, sizeof(buffer) - 1);
if (n == sizeof(buffer) - 1)
continue;
buffer[n] = 0;
if (parse_sensor_packet(buffer, &pd) == 0) continue;
if(fabs(pd.ax) > SENSE_DELTA) {
//printf("ax: %f\r\n", pd.ax);
}
if(fabs(pd.ay) > SENSE_DELTA) {
//printf("ay: %f\r\n", pd.ay);
}
if (pd.ax > 0) {
led_left = 0;
led_right = fabs(pd.ax) * 2;
} else {
led_left = fabs(pd.ax) * 2;
led_right = 0;
}
if (pd.ay > 0) {
led_up = 0;
led_down = fabs(pd.ay) * 2;
} else {
led_up = fabs(pd.ay) * 2;
led_down = 0;
}
}
}
int main() {
lcd.cls();
ethernet_init();
main_loop();
}
