LED not turning off completely
hey guys!
sorry if not right place im having little problem controling led
here code..... see video below preview on whats going on.....
https://www.youtube.com/watch?v=grdnrupxzbe
sorry if not right place im having little problem controling led
here code..... see video below preview on whats going on.....
code: [select]
#include <spi.h>
#include <ethernet.h>
int led = 8;
string post = "";
string set = "";
// enter mac address , ip address controller below.
// ip address dependent on local network:
byte mac[] = {
0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };
ipaddress ip(192,168,5,177);
// initialize ethernet server library
// ip address , port want use
// (port 80 default http):
ethernetserver server(105);
void setup() {
// open serial communications , wait port open:
serial.begin(9600);
while (!serial) {
; // wait serial port connect. needed leonardo only
}
// start ethernet connection , server:
ethernet.begin(mac, ip);
server.begin();
serial.print("server @ ");
serial.println(ethernet.localip());
pinmode(led, output);
}
void loop() {
// listen incoming clients
ethernetclient client = server.available();
digitalwrite(led, high);
if (client) {
serial.println("new client");
// http request ends blank line
boolean currentlineisblank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
serial.write(c);
// if you've gotten end of line (received newline
// character) , line blank, http request has ended,
// can send reply
if (c == '\n' && currentlineisblank) {
// after double cr-lf variables are
// read line!
string post = "";
while(client.available())
{
c = client.read();
// save variables somewhere
post += c;
}
if(post != "")
{
if(post == "led=1"){
set = "on";
serial.println("on");
}else{
set = "off";
serial.println("off");
}
}
// send standard http response header
client.println("http/1.1 200 ok");
client.println("content-type: text/html");
client.println("connnection: close");
client.println();
client.println("<!doctype html>");
client.println("<html><head><title>led control</title>");
client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />");
client.println("<link href='http://fonts.googleapis.com/css?family=fjord+one' rel='stylesheet' type='text/css'>");
client.println("<style>*{font-family:'fjord one';}body{background-color:#f2f2f2;}h1{color:#222;}</style>");
client.println("</head><body><h1>led control</h1>");
client.print("<form method='post'>");
client.print("<input type=\"radio\" name=\"led\" value=\"0\" onclick=\"this.form.submit()\"");
if(set != "on"){
client.print(" checked");
}
client.print(">off<br />");
client.print("<input type=\"radio\" name=\"led\" value=\"1\" onclick=\"this.form.submit()\"");
if(set == "on"){
client.print(" checked");
}
client.print(">on<br />");
client.print("</form>");
client.println("</body></html>");
break;
}
if (c == '\n') {
// you're starting new line
currentlineisblank = true;
}
else if (c != '\r') {
// you've gotten character on current line
currentlineisblank = false;
}
}
}
// give web browser time receive data
delay(1);
// close connection:
client.stop();
serial.println("client disonnected");
}
if(set == "on"){
digitalwrite(led, high);
}else{
digitalwrite(led, low);
}
}
https://www.youtube.com/watch?v=grdnrupxzbe
hey kelly,
can send me schematic? know sounds silly let's make sure led being driven properly. happening on 1 end you're driving high side digital pin , on other have floating point voltage, not ground.
other printing make sure hit 'digitalwrite(pin,low)' , if do, put delay in there, see if changes anything.. maybe you're popping out of logic , writing high. though suspect it's former, not latter.
cheers!
can send me schematic? know sounds silly let's make sure led being driven properly. happening on 1 end you're driving high side digital pin , on other have floating point voltage, not ground.
other printing make sure hit 'digitalwrite(pin,low)' , if do, put delay in there, see if changes anything.. maybe you're popping out of logic , writing high. though suspect it's former, not latter.
cheers!
Arduino Forum > Using Arduino > LEDs and Multiplexing > LED not turning off completely
arduino
Comments
Post a Comment