Show Posts
|
|
Pages: [1] 2 3 ... 11
|
|
1
|
Using Arduino / Networking, Protocols, and Devices / Re: Network Led and switches
|
on: April 27, 2013, 04:59:57 pm
|
ok Figured it out with my own last statement,,, that way some one else besides me will know. The error was due to the fact it was running still inside the clients code.. { } the manual coding wasnt past that part. PaulS said "client wants to turn LED on" code from the "owner wants to turn LED on" code not sure if that was the thought was. so there is a little insight into the details of coding  careful where you put your *cough* code  Now its time to clean it up and consolidate all that and add more stuff  --- at least the base coding is working. 
|
|
|
|
|
2
|
Using Arduino / Networking, Protocols, and Devices / Re: Network Led and switches
|
on: April 27, 2013, 04:24:50 pm
|
Ok I have cleaned alot of the coding that you were talking about. You want to separate the "client wants to turn LED on" code from the "owner wants to turn LED on" code. So after all that, The Code will operate the Pin But only of I am holding the button and hit Refresh on the browser, So I am guessing it is cause the other code can not run independant of the client request. Does that seem correct? if so what direction of coding should I be looking twards ? I could make if refresh ever second and hope it catches the button state. But that would be silly  #include <SPI.h> #include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xA9, 0xDA }; //mac address byte ip[] = { 192, 168, 0, 110 }; // ip stuff byte gateway[] = {192, 168, 0, 1 }; byte subnet[] = { 255, 255, 255, 0 }; EthernetServer server(80); //server port
String readString;
boolean on = false; int ledState = LOW; int onButton = 5; int offButton = 4; int ledOutPin = 6; int buttonState = LOW; void setup(){
pinMode(ledOutPin, OUTPUT); //pin to control
pinMode(onButton, INPUT); pinMode(offButton, INPUT); //start Ethernet Ethernet.begin(mac, ip, gateway, subnet); server.begin();
//enable serial data print Serial.begin(9600); Serial.println("server starting "); // }
void loop(){ int onButtonState = digitalRead(onButton); int offButtonState = digitalRead(offButton);
// client connection EthernetClient client = server.available();
if (client) { while (client.connected()) { if (client.available()) { char c = client.read();
if (readString.length() < 10) {
//store characters readString += c; }
//if HTTP request has ended if (c == '\n') {
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page client.println("Content-Type: text/html"); client.println();
client.println("<HTML>"); client.println("<HEAD>"); client.println("<TITLE>My First test</TITLE>"); client.println("</HEAD>"); client.println("<BODY>");
client.println("The Current Status of the Led Is");
delay(10); ///////////////////// control arduino pin
if (readString.indexOf("off") >0) { digitalWrite(ledOutPin, LOW); on = false; } if (readString.indexOf("on") >0) {
digitalWrite(ledOutPin, HIGH); on = true; } if (on ==1) { Serial.println("Led on"); client.println("<a href=\"/?off\"\">Led Is On</a>"); } if (on ==0) { Serial.println("Led off"); client.println("<a href=\"/?on\"\">Led Is Off</a>"); } client.println("</BODY>"); client.println("</HTML>");
//clearing string for next read readString=""; client.stop(); } // Manual section for buttons if (onButtonState == HIGH) {
digitalWrite(ledOutPin, HIGH); on = true; }
if (offButtonState == HIGH) {
digitalWrite(ledOutPin, LOW); on = false; }
delay(10);
//delay(10); Serial.print(buttonState); } } } }
|
|
|
|
|
3
|
Using Arduino / Networking, Protocols, and Devices / Re: Network Led and switches
|
on: April 27, 2013, 09:33:40 am
|
Ok I did a little different approch from what you indicated ( maybe my down fall) I created a call for all the change states to call to. 1 digital write at te end, with a basic switch state. but still for soem reason it only can be modified from the Client call. So i remarked almost every thing for a ethernet client code and the switches operate the led correctly. So it is some programing conflict with how it or me has stated it (lol now i have the crap remarked out of it ) #include <SPI.h> #include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xA9, 0xDA }; //mac address byte ip[] = { 192, 168, 0, 110 }; // ip stuff byte gateway[] = { 192, 168, 0, 1 }; byte subnet[] = { 255, 255, 255, 0 }; EthernetServer server(80); //server port
String readString;
int on = 0; int ledState = LOW; int onButton = 5; int offButton = 4; int ledOutPin = 6; int buttonState = LOW; void setup(){
pinMode(ledOutPin, OUTPUT); //pin to control
pinMode(onButton, INPUT); pinMode(offButton, INPUT); //start Ethernet Ethernet.begin(mac, ip, gateway, subnet); server.begin();
//enable serial data print Serial.begin(9600); Serial.println("server "); // }
void loop(){ int onButtonState = digitalRead(onButton); int offButtonState = digitalRead(offButton);
if (onButtonState == HIGH) {
buttonState = HIGH; delay(5); } if (offButtonState == HIGH) {
buttonState = LOW; delay(5); }
// client connection EthernetClient client = server.available(); /////// <--- work if all is remarked after here if (client) { //while (client.connected()) { //if (client.available()) { char c = client.read(); /* ///////// <-- stopped working here //read HTTP request if (readString.length() < 100) {
//store characters readString += c;
}
//if HTTP request has ended if (c == '\n') {
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page client.println("Content-Type: text/html"); client.println();
client.println("<HTML>"); client.println("<HEAD>"); client.println("<TITLE>My First test</TITLE>"); client.println("</HEAD>"); client.println("<BODY>");
client.println("The Current Status of the Led Is");
delay(10); //stopping client
///////////////////// control arduino pin if (readString.indexOf("off") >0) //checks for on { on = !on; //digitalWrite(6, on ? HIGH:LOW); buttonState = LOW; // set pin }
if (readString.indexOf("on") >0) //checks for off { on = !on; //digitalWrite(6, on ? HIGH:LOW); // set pin buttonState = HIGH; }
if (on ==1) { Serial.println("Led on"); client.println("<a href=\"/?off\"\">Led Is On</a>"); } if (on ==0) { Serial.println("Led off"); client.println("<a href=\"/?on\"\">Led Is Off</a>"); } client.println("</BODY>"); client.println("</HTML>"); client.stop();
//clearing string for next read readString="";
}
*/
digitalWrite(ledOutPin,buttonState); delay(10);
//delay(10); Serial.print(buttonState); } } } }
the last Code Copy is the unworking Version
|
|
|
|
|
4
|
Using Arduino / Networking, Protocols, and Devices / Re: Network Led and switches
|
on: April 27, 2013, 08:28:06 am
|
Yes, independent control of the same Pin is the goal  it just odd (to me) that in this sketch that it does not operate that way. How can a simple "digitalWrite" not take effect from a simple switch, while I thought the other part of the code was running independant. I am just not sure why one effects the other. What do you think ?
|
|
|
|
|
6
|
Using Arduino / Networking, Protocols, and Devices / SOLVED Network Led and switches
|
on: April 26, 2013, 06:38:28 pm
|
I'm trying to use a Network page and a Switch to turn on/off the same Led/Pin. I have no problem using the Web URL but if i and a simple digitalWrite to control the Same pin, It does not operate that pin, But I can still control it with the URL. I can copy the sketch for the Switch and Led pin into a stand alone Sketch and it operates. Is the something in a "readString.indexOf" that has soemthing that I'm not aware of, or am I on the wrong track. Heres is my sketch with lots of trials and tests mixed in it with remarks and all. you'll see some stuf i was trying also. Thought this would be a simple coding  #include <SPI.h> #include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xA9, 0xDA }; //mac address byte ip[] = { 192, 168, 0, 110 }; // ip stuff byte gateway[] = { 192, 168, 0, 1 }; byte subnet[] = { 255, 255, 255, 0 }; EthernetServer server(80); //server port
String readString;
int on = 0; //char ledValue = 0; int onButton = 5; int offButton = 4; int onButton1 = 0; int offButton1 = 0;
void setup(){
pinMode(6, OUTPUT); //pin to control pinMode(onButton, INPUT); pinMode(offButton, INPUT); //start Ethernet Ethernet.begin(mac, ip, gateway, subnet); server.begin();
//enable serial data print Serial.begin(9600); Serial.println("server "); // }
void loop(){ onButton1 = digitalRead(onButton);
offButton1 = digitalRead(offButton);
// client connection EthernetClient client = server.available(); if (client) { while (client.connected()) { if (client.available()) { char c = client.read();
//read HTTP request if (readString.length() < 100) {
//store characters readString += c;
}
//if HTTP request has ended if (c == '\n') {
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page client.println("Content-Type: text/html"); client.println();
client.println("<HTML>"); client.println("<HEAD>"); client.println("<TITLE>My First test</TITLE>"); client.println("</HEAD>"); client.println("<BODY>");
client.println("The Current Status of the Led Is");
delay(1); //stopping client
///////////////////// control arduino pin if ((readString.indexOf("off") >0) || (offButton1 == HIGH)) //checks for on { on = !on; //digitalWrite(6, on ? HIGH:LOW); digitalWrite(6, LOW); // set pin }
if ((readString.indexOf("on") >0) || (onButton1 == HIGH)) //checks for off { on = !on; //digitalWrite(6, on ? HIGH:LOW); // set pin digitalWrite(6, HIGH); } /* if (onButton1 == HIGH) { digitalWrite(6,HIGH); delay(500); } if (offButton1 == HIGH) { digitalWrite(6,LOW); delay(500); }
*/
if (on ==1) { Serial.println("Led on"); client.println("<a href=\"/?off\"\">Led Is On</a>"); } if (on ==0) { Serial.println("Led off"); client.println("<a href=\"/?on\"\">Led Is Off</a>"); } client.println("</BODY>"); client.println("</HTML>"); client.stop();
//clearing string for next read readString="";
}
} } } }
any track for me to follow would be great 
|
|
|
|
|
11
|
Using Arduino / Displays / Re: How to use LCD with Arduino Mega 2560
|
on: May 12, 2012, 08:08:58 am
|
none are set in stone here is mine LiquidCrystal lcd(52,50,48,46,44,42); compaired to LiquidCrystal lcd(12, 11, 5, 4, 3, 2); you just have to keep them in the same order
|
|
|
|
|
12
|
Using Arduino / Networking, Protocols, and Devices / Re: Float I2c
|
on: May 07, 2012, 07:10:52 pm
|
Holy Crap, Ty for the info -I would have never expected a complete sketch tyvm  . Now i have to break it down to get the idea of how its works, then to incorporate into my increasingly growing sketch. thank you again 
|
|
|
|
|
15
|
Using Arduino / Networking, Protocols, and Devices / Float I2c
|
on: May 06, 2012, 04:20:17 pm
|
Is there a nice simple way to Pass Float Value over I2C -to a second arduino- (example 3.12 for Volts). All ive seen is elaborate unions and pointers ,, Seems WAY over complexe so i skipped reading further. Any thoughts/ideas /Examples/referances  ?
|
|
|
|
|