Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
#include <SPI.h>#include <Ethernet.h>// Enter a MAC address and IP address for your controller below.// The IP address will be dependent on your local network.// gateway and subnet are optional:byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };byte ip[] = { 192,168,1, 177 };byte gateway[] = { 192,168,1, 1 };byte subnet[] = { 255, 255, 0, 0 };pinMode(2, OUTPUT);pinMode(3, OUTPUT);// telnet defaults to port 23Server server(23);boolean connected = false;void setup() { // initialize the ethernet device Ethernet.begin(mac, ip, gateway, subnet); // start listening for clients server.begin(); // open the serial port Serial.begin(9600);}void loop() { // wait for a new client: Client client = server.available(); if (client) { connected = true; } // read the bytes incoming from the client: char thisChar = client.read(); //AND HERE THERE WOULD A SELECT CASE DOING DIFFERENT THINGS DEPENDING ON WHAT BYTE THE ARDUINO RECIEVED. //for example either turning pin 2 or 3 high. //digitalWrite(2, HIGH); //digitalWrite(3, HIGH); //which would make my motor go either backwards or forwards. }}
[quote author=GalacticNerd link=topic=14556.msg106375#msg106375 date=1317471260] // read the bytes incoming from the client: char thisChar = client.read(); //AND HERE THERE WOULD A SELECT CASE DOING DIFFERENT THINGS DEPENDING ON WHAT BYTE THE ARDUINO RECIEVED. //for example either turning pin 2 or 3 high. //digitalWrite(2, HIGH); //digitalWrite(3, HIGH); //which would make my motor go either backwards or forwards. }}
Code: [Select][quote author=GalacticNerd link=topic=14556.msg106375#msg106375 date=1317471260] // read the bytes incoming from the client: char thisChar = client.read(); //AND HERE THERE WOULD A SELECT CASE DOING DIFFERENT THINGS DEPENDING ON WHAT BYTE THE ARDUINO RECIEVED. //for example either turning pin 2 or 3 high. //digitalWrite(2, HIGH); //digitalWrite(3, HIGH); //which would make my motor go either backwards or forwards. }}That looks like a pretty good start to me. I don't understand the question I guess. Have you tried doing that and you're not getting the results you want?Joe
#include <SPI.h>#include <Ethernet.h>// Enter a MAC address and IP address for your controller below.// The IP address will be dependent on your local network.// gateway and subnet are optional:byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };byte ip[] = { 192,168,1, 177 };byte gateway[] = { 192,168,1, 1 };byte subnet[] = { 255, 255, 0, 0 };pinMode(2, OUTPUT);pinMode(3, OUTPUT);// telnet defaults to port 23Server server(23);boolean connected = false;void setup() { // initialize the ethernet device Ethernet.begin(mac, ip, gateway, subnet); // start listening for clients server.begin(); // open the serial port Serial.begin(9600);}void loop() { // wait for a new client: Client client = server.available(); if (client) { connected = true; } // read the bytes incoming from the client: char thisChar = client.read(); switch (incomingChar) { case 1: //forward digitalWrite(3, LOW); digitalWrite(2, HIGH); break; case 2: //backward digitalWrite(3, HIGH); digitalWrite(2, LOW); break; default: //make sure it's not moving digitalWrite(3, LOW); digitalWrite(2, LOW); break; } }}
Are you asking what functions to call for serial communications? If so The arduino site has a reference page that explains all their functions. They also have a section on libraries other than the built in ones. This should give you what you need, look for the serial section:http://arduino.cc/en/Reference/HomePageJoe