Hi guys,
I'm not a good programmer. I'm a beginner only.
I have 1 question. I made a code :
int cap1 = 2;
int cap2 = 3;
int cap3 = 4;
int cap4 = 5;
int cod1 = 9;
int cod2 = 10;
int cod3 = 11;
int cod4 = 12;
int cod5 = 13;
void setup (){
pinMode(cap1, INPUT_PULLUP);
pinMode(cap2, INPUT_PULLUP);
pinMode(cap3, INPUT_PULLUP);
pinMode(cap4, INPUT_PULLUP);
pinMode(cod1, OUTPUT);
pinMode(cod2, OUTPUT);
pinMode(cod3, OUTPUT);
pinMode(cod4, OUTPUT);
pinMode(cod5, OUTPUT);
Serial.begin(9600);
}
void loop (){
fonction1();
delay(2000);
digitalWrite(cod1, LOW);
digitalWrite(cod2, LOW);
digitalWrite(cod3, LOW);
digitalWrite(cod4, LOW);
digitalWrite(cod5, LOW);
fonction2();
delay(2000);
digitalWrite(cod1, LOW);
digitalWrite(cod2, LOW);
digitalWrite(cod3, LOW);
digitalWrite(cod4, LOW);
digitalWrite(cod5, LOW);
fonction3();
delay(2000);
digitalWrite(cod1, LOW);
digitalWrite(cod2, LOW);
digitalWrite(cod3, LOW);
digitalWrite(cod4, LOW);
digitalWrite(cod5, LOW);
}
void fonction1 (){
int capteur1 = digitalRead(cap1);
digitalWrite(cod2, HIGH);
digitalWrite(cod4, HIGH);
if (capteur1 == HIGH){
Serial.println("S1 = 50%");
}
else{
Serial.println("S1 = 100%");
}
delay(1);
}
void fonction2 (){
int capteur2 = digitalRead(cap2);
digitalWrite(cod1, HIGH);
digitalWrite(cod3, HIGH);
if (capteur2 == HIGH){
Serial.println("S2 = 50%");
}
else{
Serial.println("S2 = 100%");
}
delay(1);
}
void fonction3 (){
int capteur3 = digitalRead(cap4);
digitalWrite(cod1, HIGH);
digitalWrite(cod5, HIGH);
if (capteur3 == HIGH){
Serial.println("S3 = 50%");
}
else{
Serial.println("S3 = 100%");
}
delay(1);
}
And I want that Serial.println switch to client.println. Wich is viewable by a webpage.
I have this part of a code that I found. This is I think the basic lines of a webserver html page.
#include <SPI.h>
#include <Ethernet.h>
// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 20); // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80
void setup()
{
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin(); // start to listen for clients
}
void loop ()
{
{
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 2");
client.println();
// envoyerla page web en ''PRINT''
client.println("<!DOCTYPE html>");
client.println("<html>");
client.println("<head>");
client.println("<title>Serveur 1.0</title>");
client.println("</head>");
client.println("<body>");
client.println("<h1><center>Serveur V1.0</center></h1>");
// maybe the client.println here ??
client.println("</body>");
client.println("</html>");
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
}
Could I merge them togheter???
thank you everybody.