hello, I'm new in arduino. hope anyone can help me to guide me and show me the way to solve my problem. I'm having some logic error which is when i'm try to load image from my SD Card,the HTML output get what i want but it also show some symbols or words that i really don't know what's the problem with my code.
i attach the image of the logic error..
here is my code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 6 }; // ip in lan
EthernetServer server(80); //server port
String readString;
String s;
String ss;
//////////////////////
void setup(){
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT); //pin selected to control
pinMode(7, OUTPUT); //pin selected to control
pinMode(8, OUTPUT); //pin selected to control
pinMode(9, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
//start Ethernet
//enable serial data print
Serial.begin(9600);
// disable w5100 while setting up SD
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
Serial.print("Starting SD..");
if(!SD.begin(4)) Serial.println("failed");
else Serial.println("ok");
Serial.println("server multi pin button test 1.0"); // so I can keep track of what is loaded
Ethernet.begin(mac, ip);
server.begin();
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(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("Connection: keep-alive");
client.println();
File myFile = SD.open("kpm.jpg");
if(myFile){
byte clientBuf[64];
int clientCount = 0;
while(myFile.available())
{
clientBuf[clientCount] = myFile.read();
clientCount++;
if(clientCount > 63)
{
// Serial.println("Packet");
client.write(clientBuf,64);
clientCount = 0;
}
}
if(clientCount > 0) client.write(clientBuf,clientCount);
// close the file:
myFile.close();
}
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>LED NOTIFY STATUS</TITLE>");
client.println("</HEAD>");
client.println("<body style='background-color:rgb(255,255,204);'>");
client.println("<img src= kpm.jpg >");
client.println(" <font color=black><H1 align=center>LECTURER STATUS</font> </H1>
");
client.println("*******PLEASE DOUBLE CLICK ON THE BUTTON ********");
// For simple testing, pin 5, 6, 7, and 8 are used in buttons
client.println("<font color=black><H2 align=center>Day</font> </H2>");
// mousedown buttons
client.println("<input type=button value=ISNIN onmousedown=location.href='/?ISNIN2;'>");
client.println("<input type=button value=SELASA onmousedown=location.href='/?SELASA3;'>");
client.println("<input type=button value=RABU onmousedown=location.href='/?RABU5;'>");
client.println("<input type=button value=KHAMIS onmousedown=location.href='/?KHAMIS6;'>");
client.println("<input type=button value=JUMAAT onmousedown=location.href='/?JUMAAT7;'>");
client.println(" <input type=button value='ALL OFF' onmousedown=location.href='/?off4;'>
");
client.println(s);
client.println("<font color=black><H2 align=center>STATUS</font> </H2>");
client.println("<input type=button value=ADA onmousedown=location.href='/?ada8;'>");
client.println("<input type=button value=KELAS onmousedown=location.href='/?kelas9;'>");
client.println("<input type=button value=BERCUTI onmousedown=location.href='/?bcuti@;'>");
client.println("<input type=button value=MESYUARAT onmousedown=location.href='/?mesyuarat%;'>");
client.println("<input type=button value=BERTUGAS DILUAR onmousedown=location.href='/?btgsDLuar$;'>");
client.println(" <input type=button value='ALL OFF' onmousedown=location.href='/?off10;'>
");
client.println(ss);
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readString.indexOf('2') >0)//checks for 2
{
s=("ISNIN");
digitalWrite(2, HIGH); // set pin 5 high
Serial.println("Led 2 On");
}
if(readString.indexOf('3') >0)//checks for 3
{
s=("SELASA");
digitalWrite(3, HIGH); // set pin 5 low
Serial.println("Led 3 On");
}
if(readString.indexOf('5') >0)//checks for 4
{
s=("RABU");
digitalWrite(5, HIGH); // set pin 6 high
Serial.println("Led 5 On");
}
if(readString.indexOf('6') >0)//checks for 5
{
s=("KHAMIS");
digitalWrite(6, HIGH); // set pin 6 low
Serial.println("Led 6 On");
}
if(readString.indexOf('7') >0)//checks for 6
{
s=("JUMAAT");
digitalWrite(7, HIGH); // set pin 7 high
Serial.println("Led 7 On");
}
if(readString.indexOf('4') >0)//checks for 7
{
s=("OFF");
digitalWrite(2, LOW); // set pin 7 low
digitalWrite(3, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
Serial.println("All Led OFF");
}
if(readString.indexOf('8') >0)//checks for 2
{
ss=("ADA");
digitalWrite(8, HIGH); // set pin 5 high
Serial.println("Led 8 On");
}
if(readString.indexOf('9') >0)//checks for 3
{
ss=("KELAS");
digitalWrite(9, HIGH); // set pin 5 low
Serial.println("Led 9 On");
}
if(readString.indexOf('@') >0)//checks for 4
{
ss=("BERCUTI");
digitalWrite(11, HIGH); // set pin 6 high
Serial.println("Led 11 On");
}
if(readString.indexOf('%') >0)//checks for 5
{
ss=("MESYUARAT");
digitalWrite(12, HIGH); // set pin 6 low
Serial.println("Led 12 On");
}
if(readString.indexOf('
please help me and teach me how...
thank you ![]()
{
ss=("BERTUGAS DI LUAR");
digitalWrite(13, HIGH); // set pin 7 high
Serial.println("Led 13 On");
}
if(readString.indexOf('10') >0)//checks for 7
{
ss=("STATUS OFF");
digitalWrite(8, LOW); // set pin 7 low
digitalWrite(9, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
Serial.println("All Led OFF");
}
//clearing string for next read
readString="";
}
}
}
}
}
please help me and teach me how...
thank you :)


