Whats wrong with this?
i found code on youtube, in video system seems work really well. heres code supplied when compile error:
sketch_jan26a:145: error: stray '\' in program
sketch_jan26a:145: error: expected constructor, destructor, or type conversion @ end of input
i know simple , i'll embarrassed when find it!
sketch_jan26a:145: error: stray '\' in program
sketch_jan26a:145: error: expected constructor, destructor, or type conversion @ end of input
i know simple , i'll embarrassed when find it!
code: [select]
#include <ethernet.h>
#include <spi.h>
byte mac[] = { 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };
byte ip[] = { 192, 168, 0, 177 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
string instring = string(35);
string channel;
string name[] = {"null","kitchen","living room","hall","closet","bedroom","office"};
//pins 10, 11, 12 , 13 reserved ethernet module.
int old[] = {00,0,0,0,0,0,0};//old switch value
int swch[] = {00,a0,a1,a2,a3,a4,a5};//switch input pins
int arm = 8;//away armed input pin
int armed =0;//value of 1 when armed
int channelpin[] = {00, 2, 3, 4 ,5 ,6 ,7}; //channel output pins. 00 null pin
int numofchannels = 6; //number of channels
string value[] = {"off","off","off","off","off","off","off"}; //startup channels off
ethernetserver server(80);
string data;
int debounce = 200;
void setup(){
serial.begin(9600);
ethernet.begin(mac, ip,gateway,subnet);
server.begin();
//set pin mode
(int j = 1; j < (numofchannels + 1); j++){
pinmode(channelpin[j], output);
}
pinmode(arm, input);
serial.println("serial ready");
serial.println("ethernet ready");
serial.println("server ready");
}
void loop(){
ethernetclient client = server.available();
//test internal switching
for(int i=1;i < (numofchannels + 1) ;i++){
if(digitalread(swch[i])==!old[i]){
delay(debounce);
if(digitalread(swch[i])==!old[i]){
if(value[i] == "on"){
digitalwrite(channelpin[i], low);
value[i] = "off";
serial.println(name[i]+" off internal");
}
else if(value[i] == "off"){
digitalwrite(channelpin[i], high);
value[i] = "on";
serial.println(name[i]+" on internal");
}
}
old[i] = digitalread(swch[i]);
}
}
if(client){
boolean current_line_is_blank = true;
while (client.connected()) {
if(client.available()) {
char c = client.read();
if (instring.length() < 35) {
instring.concat(c);
}
if (c == '\n' && current_line_is_blank) {
// send standard http response header
client.println("http/1.1 200 ok");
client.println("content-type: text/html");
client.println();
client.println("<html><body><form method=get>");
// client.println("<p><font size=7>locust home lighting controller</p>"); header not used
for(int i=1;i < (numofchannels + 1) ;i++){
channel = string("channel") + i;
if(instring.indexof(channel+"=off")>0 || instring.indexof("all=on")>0){
serial.println(name[i]+" on ethernet");
digitalwrite(channelpin[i], high);
value[i] = "on";
}else if(instring.indexof(channel+"=on")>0 || instring.indexof("all=off")>0 ){
serial.println(name[i]+" off ethernet");
digitalwrite(channelpin[i], low);
value[i] = "off";
}
//if statments change color of radio button
if((value[i])== "on"){ //changes yellow background if on
client.println("<br><font size=7><input type=submit style=background-color:yellow;width:150px;height:60px;font-size:50px name="+channel+" value="+value[i]+" > "+name[i]+"");
}
else if((value[i])== "off"){ //normal background if off
client.println("<br><font size=7><input type=submit style=width:150px;height:60px;font-size:50px name="+channel+" value="+value[i]+" > "+name[i]+"");
}
}
client.println("<br><font size=7>all <input type=submit style=width:150px;height:60px;font-size:50px name=all value=off><input type=submit style=width:150px;height:60px;font-size:50px name=all value=on>");
client.println("</from></html></body>");
break;
}
if (c == '\n') {
// we're starting new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten character on current line
current_line_is_blank = false;
}
}
}
// give web browser time receive data
delay(1);
instring = "";
client.stop();
}
//away arm program turn lights off
if(digitalread(arm)==high){
delay(500);
if(digitalread(arm)==high){
for(int i=1;i < (numofchannels + 1) ;i++){
digitalwrite(channelpin[i], low);
value[i]= "off";
armed= 1;
}
}
}
//away arm program turn lights on
else if(digitalread(arm)==low && armed==1){
for(int i=1;i < (numofchannels + 1) ;i++){
digitalwrite(channelpin[i], high);
value[i]= "on";
armed= 0;
}
}
delay(5); //keeps arduino loops running @ slower speed
}
when copied arduino ide after last } dot appears. not full stop not apostrophe im not sure after removing code verified
Arduino Forum > Using Arduino > Project Guidance > Whats wrong with this?
arduino
Comments
Post a Comment