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±Ç ±¸¸ÅÇؾßÇÒ°Å°°¾Æ¿ä~¤»¤»