타이머 ticker 를 2개로 늘리고 ADC 를 살려 봤다.
------------------ 참고소스 ----------------------
#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;
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);
flipper1.attach(0.3, flip_test); //start , ms
flipper2.attach(1, 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("1");
break;
case 1:
Serial.printf("2");
break;
case 2:
Serial.printf("3");
break;
case 3:
Serial.printf("4 , A: %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 따라하기 (0) | 2018.03.12 |
---|---|
nodeMCU wifi 연결 (0) | 2018.03.12 |
nodeMCU 참고 사이드 (0) | 2018.03.10 |
nodeMCU pin MAP 다시보기 (0) | 2018.03.09 |
nodeMCU 타이머(Ticker)살리기 (0) | 2018.03.09 |