HTML및 아두이노 프로그래밍에 전혀 모르는 채로 여기저기서 주워온 코드를 응용하여 만들다보니
1번 버튼을 누르면 연결된 릴레이 제어는 가능하지만,2번 버튼을 누르면 2번이 아닌 1번 릴레이가 작동하는 상황입니다.
2번 릴레이와 연결된 핀헤더를 정의 해주고 웹서버상의 2번 버튼과 연동하면 될듯한데 프로그래밍을 하나도 몰라서 어찌해야할지 모르겠습니다.
도움주시면 감사하겠습니다.
/*
PUMP CONTROL SYSTEM
*/
#include <SPI.h>
#include <Ethernet.h>
int led = 4;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 66 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(led, OUTPUT);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
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();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
client.println("<TITLE>PUMP CONTROL SYSTEM</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>PUMP CONTROL SYSTEM</H1>");
client.println("<hr />");
client.println("<br />");
client.println("<H2>169-1</H2>");
client.println("<br />");
client.println("<a href=\"/?button1on\"\">Turn OFF PUMP1</a>");
client.println("<a href=\"/?button1off\"\">Turn ON PUMP1</a><br />");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/?button2on\"\">Turn OFF PUMP2</a>");
client.println("<a href=\"/?button2off\"\">Turn ON PUMP2</a><br />");
client.println("<p>-</p>");
client.println("<br />");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0){
digitalWrite(led, HIGH);
}
if (readString.indexOf("?button1off") >0){
digitalWrite(led, LOW);
}
if (readString.indexOf("?button2on") >0){
digitalWrite(led, HIGH);
}
if (readString.indexOf("?button2off") >0){
digitalWrite(led, LOW);
}
//clearing string for next read
readString="";
}
}
}
}
}
LED 4 .. 4 ɿ 1 Ǿִ° ϴ?
³?
int led2 = 5 ؼ .. 5 2 Ͻð
pinMode(led, OUTPUT);
Ʒʿ
pinMode(led2, OUTPUT);
Ʒʿ ̺κ
if (readString.indexOf("?button2on") >0){
digitalWrite(led, HIGH);
}
if (readString.indexOf("?button2off") >0){
digitalWrite(led, LOW);
}
led -> led2 ֽø ɰ .
if (readString.indexOf("?button2on") >0){
digitalWrite(led2, HIGH);
}
if (readString.indexOf("?button2off") >0){
digitalWrite(led2, LOW);
}
̷ غ ؾұ?
å Դµ ʹ ӱ ٷµؼ 뿩Ϸ ҽϴ.
۸ ְϱ?
ϴ ѵΰ ð ... .. ǰ ص °
̱ մϴ.. ܵ ϴ° .. ϴ ..
¶.. øŰ ٷ Ͻô κ ηϴ..
ʾƼ .. Ͻź ηϴ.. ϼż ñ ٶԿ.
ϰ ʿ κи Ĵ (?) ־ ....
ϴ å 1̶ ؼ ̽ ͵ ۸ ϸ ߰ڽϴ...
Ƶ̳ 1, HTML1 ؾҰŰƿ~