Arduino: Ethernet UDP Send isi 1 Analog Input 0
Revision as of 09:10, 3 January 2016 by Onnowpurbo (talk | contribs) (New page: ==Code== →UDPSendAnalogInput: created 27 Nov 2015 by Onno W. Purbo This code is in the public domain.: #include <SPI.h> // needed for Arduino versions later than 0...)
Code
/* UDPSendAnalogInput: created 27 Nov 2015 by Onno W. Purbo This code is in the public domain. */ #include <SPI.h> // needed for Arduino versions later than 0018 #include <Ethernet.h> #include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008 // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 0, 3); unsigned int localPort = 8888; // local port to listen on // An EthernetUDP instance to let us send and receive packets over UDP EthernetUDP Udp; IPAddress remoteIP(192,168,0,100); unsigned int remotePort = 8888; void setup() { // start the Ethernet and UDP: Ethernet.begin(mac, ip); Udp.begin(localPort); Serial.begin(9600); } void loop() { Udp.beginPacket(remoteIP, remotePort); int sensorReading = analogRead(0); Udp.print(sensorReading); Udp.write("\n"); delay(100); }