Sending POT read values via UDP


i have arduino ethernet using read pot values on simulator, want send these values computer simulator software on can input game.

i doing via udp guy wrote program integrate game said easier way , recording data the controls (for research purposes) easier. regardless of whether true, can not change this.

i trying write code send values read pot processing code displays value. intermediate step before try , integrate code game etc. beginner regards programming in respect, have been thrown in @ deep end here. while can program, has been making mathematical programs matlab.

i have tried modify code given in examples , have ended following not working:

aruino code:
(arduino code code tags - learn use them please.  moderator)
code: [select]

#include <spi.h>         // needed arduino versions later 0018
#include <ethernet.h>
#include <ethernetudp.h>         // udp library from: bjoern@cs.stanford.edu 12/30/2008


// enter mac address , ip address controller below.
// ip address dependent on local network:
byte mac[] = {
  0x90, 0xa2, 0xda, 0x0f, 0xc6, 0x1f
};
ipaddress ip(192, 168, 0, 177);

unsigned int localport = 8888;      // local port listen on

// buffers receiving , sending data
char packetbuffer[udp_tx_packet_max_size]; //buffer hold incoming packet,
char  replybuffer[] = "acknowledged";       // string send back

// ethernetudp instance let send , receive packets on udp
ethernetudp udp;

int potpin = 2;    // select input pin potentiometer
int val = 0;       // variable store value coming sensor
int mapped = 0;

void setup() {

  // start ethernet , udp:

  ethernet.begin(mac,ip);

  udp.begin(localport);

}



void loop() {
 
  val = analogread(potpin);  // read value sensor
  mapped = map(val, 0, 1023, 0, 5000);
 
  serial.print(analogread(potpin));
  serial.print(mapped);   
  delay (400);
 
  udp.beginpacket(udp.remoteip(), udp.remoteport());

    udp.write(mapped);

    udp.endpacket();

}

processing code:
(code tags work here too...)
code: [select]

 import hypermedia.net.*;

 udp udp;  // define udp object
 string value = "0";

 void setup() {
 size(480,640);
 background(0);
 smooth();
 udp = new udp( this, 3000 );  // create new datagram connection on port 6000
 udp.log( true );     // <-- printout connection activity
 udp.listen( true );           // , wait incoming message
 }

 void receive( byte[] data ) {       // <-- default handler
 //void receive( byte[] data, string ip, int port ) {  // <-- extended handler
 
  value=new string(data);
  println(value);

 }

 void draw()
 {
  fill(50);
  if (value != "0") {
  text(value, 10, 10, 70, 80);
  }

 }

note: there maybe uneccesary lines in there have failed delete code modified. mapped value of analogue read im not sure range of values game want receive of yet.

thanks help!

quote
but not working:
how so? no 1 has hardware setup. do, not do, etc.


Arduino Forum > Using Arduino > Programming Questions > Sending POT read values via UDP


arduino

Comments