______________________________________________________________________________________________________________________________
WeMos 보드에서 붙박이 LED가 아니라 별도의 LED를 설치하여 WiFi 에 의한 원격BLINKING 제어를 해 보자. BLINKIG은 LED on 과 OFF 사이에 적저당한 시간 지연을 부여하면 깜박거리게 된다. 100 msec 이하면 좋다. 사진의 배선에서 빨판에 설치된 LED 와 가변 저항은 아두이노에서 사용하던 배선 재활용 케이스이다. WeMos 보드의 치수 규격이 아두이노 우노와 동일하기 때문에 비슷한 모양의 배선을 그대로 옮겨 사용이 가능하다. ....
나머지 내용은 아래의 블로그에 포스팅되어 있으므로 넘어가서 읽으세요.
아두이노 코딩-61: 아두이노 사물인터넷 NodeMCU Web Server 코딩에 의한 LED on OFF 특집
https://steemit.com/kr/@codingart/61-nodemcu-web-server-led-on-off
스팀잇에서 넘어 오신 분은 아래에 첨부한 코드를 받아가세요.
//WeMos_IOT_LED_BLINKING_01
#include <ESP8266WiFi.h>
const char* ssid = "android1234";//무선 공유기 id로 수정
const char* password = "dddddddddd";//무선 공유기 비빌번호
int ledPin = D3; //
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup done");
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
WiFiClient client = server.available(); // Check if a client has connected
if (!client) {
return;
}
Serial.println("new client");
while(!client.available()) { // Wait until client sends data
delay(1);
}
String request = client.readStringUntil('\r'); // Read the first line of the request
Serial.println(request);
client.flush();
int value = LOW;
if (request.indexOf("/BLINK") != -1) {
for ( int i = 0; i < 20; i++) {
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin,HIGH);
delay(100);
}
value = HIGH;
}
if (request.indexOf("/STOP") != -1) {
digitalWrite(ledPin, LOW);
value = LOW;
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<body>");
client.print("Led pin is now: ");
if(value == HIGH) {
client.print(" BLINKING");
}
else {
client.print("STOP BLINKING");
}
client.println("<br><br>");
client.println("<a href=\"/BLINK\"\"><button>BLINK </button></a>");
client.println("<a href=\"/STOP\"\"><button>STOP </button></a><br />");
client.println("</body>");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}//끝
'아두이노프로세싱 프로그래밍' 카테고리의 다른 글
Processing Client 아두이노 WeMos 웹서버 LED ON OFF 코딩 (0) | 2018.06.16 |
---|---|
Processing 아두이노 MPU6050 IMU 센서 코딩 재현 (0) | 2018.06.15 |
스타워즈 송을 Processing으로 Visualization하자 (0) | 2018.06.07 |
사물인터넷 NodeMCU Web Server 코딩에 의한 LED ON OFF 특집 (0) | 2018.06.06 |
아두이노 난수발생기가 인터페이스된 Processing 시계 코딩(짤) (0) | 2018.06.05 |