C++

CAN_arduino_f

CAN통신을 응용한 아두이노 학습

  • red led, green led 순차점멸
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
String str_1 = "Choose your led : ";
int num;

void setup()
{
Serial.begin(9600);
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
}
void loop()
{
Serial.print(str_1);
// 시리얼 통신으로 입력이 될때까지 기다림
while(Serial.available() == 0){
}
Serial.println(num);
num = Serial.parseInt();

if(num == 1){
digitalWrite(10,HIGH);
Serial.println("RED LED ON");
}
else if(num ==2){
digitalWrite(9,HIGH);
Serial.println("GREEN LED ON");
}
else{
digitalWrite(10,LOW);
digitalWrite(9,LOW);
}
delay(200);
}
Share