test

Dependencies:   WIZnetInterface mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "UDPSocket.h"
00003 #include "Endpoint.h"
00004 #include "EthernetInterface.h"
00005  
00006 AnalogIn analog_value(A0);
00007 
00008 #define ETH0_RST    D5
00009 #define ETH0_CS     D10
00010 #define ETH0_MOSI   D11
00011 #define ETH0_MISO   D12
00012 #define ETH0_SCK    D13
00013 
00014 Endpoint remote;
00015 EthernetInterface eth0(ETH0_MOSI, ETH0_MISO, ETH0_SCK, ETH0_CS, ETH0_RST);
00016 UDPSocket udp0;
00017  
00018 DigitalOut led(LED1);
00019 
00020 int main() {
00021     remote.set_address("192.168.91.1", 31415);
00022     eth0.connect();
00023     udp0.set_blocking(false);
00024     
00025     float meas;
00026     
00027     printf("\nAnalogIn example\n");
00028     
00029     while(1) {
00030         meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00031         meas = meas * 3300; // Change the value to be in the 0 to 3300 range
00032         //printf("measure = %.0f mV\n", meas);
00033         if (meas > 2000) { // If the value is greater than 2V then switch the LED on
00034           led = 1;
00035         }
00036         else {
00037           led = 0;
00038         }
00039         udp0.sendTo(remote, (char *)&meas, sizeof(meas));
00040         //wait(0.2); // 200 ms
00041     }
00042 }