반응형
제어의 제일 기본이면서, 제일 많이 사용하고, 제일 쉬운 제어 중하나가 온오프제어 이다.
그냥 단순하다 켜고, 꺼고 이게 전부다.
온도 값으로 만들까 하다가.
제일 쉬운 조도센서를 이용해서 만들었다.
그렇게 어렵지 않으니 소스코드 부터 봐도 될듯 하다.
#define BAUD 115200
volatile int isonoff = 0;
void setup()
{
Serial.begin(BAUD);
pinMode(8, OUTPUT);
digitalWrite(8, LOW);
isonoff = 0;
Serial.print("ARDUINO ONOFF TEST!!! \n");
}
void loop()
{
int iA0 = analogRead (A0);
int pA0 = map(iA0, 0, 1023, 0, 100);
Serial.println(pA0);
if(pA0 >= 50) do_something(1);
else do_something(0);
delay(1000);
}
void do_something(int _onoff)
{
static int ponoff = 0;
if (ponoff == _onoff) return ;
if(_onoff == 1)
{
Serial.print("LED ON \n");
digitalWrite(8, HIGH);
}
else
{
Serial.print("LED OFF \n");
digitalWrite(8, LOW);
}
delay(100);
ponoff = _onoff;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'아두이노' 카테고리의 다른 글
아두이노 on/off 제어 - #3 (0) | 2020.01.12 |
---|---|
아두이노 on/off 제어 - #2 (0) | 2020.01.12 |
아두이노와 C/C++ 이야기 -#6 (0) | 2020.01.12 |
아두이노와 C/C++ 이야기 -#5 (0) | 2020.01.10 |
아두이노와 C/C++ 이야기 -#4 (0) | 2020.01.10 |
댓글