#include <ESP8266WiFi.h>
#include <Ticker.h>
#define LED D0 //LED PIN define
#define KEY_IN D3 //Flash key pin define
#define ANALOG_IN A0 //analog in define
Ticker flipper1;
Ticker flipper2;
const char *ssid = "ssid"; // replace with your wifi ssid and wpa2 key
const char *pass = "password";
WiFiClient client;
unsigned int prt_index = 0;
unsigned char led_flag = 0;
void flip_test();
void led_test();
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(115200);
delay(10);
Serial.println("Start..");
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED, OUTPUT);
pinMode(KEY_IN, INPUT); // == pinMode(KEY_IN, INPUT);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("MAC: ");
Serial.println(WiFi.macAddress());
flipper1.attach(0.3, flip_test); //start , ms
flipper2.attach(0.5, led_test); //start , ms
//flipper.detach(); //stop
}
// the loop function runs over and over again forever
void loop() {
int buttonState = digitalRead(KEY_IN);
if (buttonState == 0)
{
Serial.printf("button key input !! \n");
}
}
//-------------------
void flip_test()
{
int inputA_val = analogRead(ANALOG_IN);
prt_index ++;
//Serial.printf("%d",prt_index);
switch (prt_index % 4)
{
case 0:
Serial.printf("^");
break;
case 1:
Serial.printf("-");
break;
case 2:
Serial.printf("^");
break;
case 3:
Serial.printf("; , B: %d \n", inputA_val);
break;
}
}
//--------------------
void led_test()
{
if (led_flag)
{
led_flag = 0;
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
}
else
{
led_flag = 1;
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
}
}
'공부 > arduino' 카테고리의 다른 글
nodeMCU Web 따라하기 2 (0) | 2018.03.12 |
---|---|
nodeMCU web 따라하기 (0) | 2018.03.12 |
nodeMCU analog input 업데이트 (0) | 2018.03.10 |
nodeMCU 참고 사이드 (0) | 2018.03.10 |
nodeMCU pin MAP 다시보기 (0) | 2018.03.09 |