-
Notifications
You must be signed in to change notification settings - Fork 0
/
led_read_control.ino
135 lines (120 loc) · 2.04 KB
/
led_read_control.ino
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
int led =5;
int turn_off =0;
String teststr;
int interruptpin = 2;
int interruptpin2 = 3;
unsigned long cnt = 0;
int button=0;
void setup(){
pinMode(led,OUTPUT);
pinMode(interruptpin, INPUT_PULLUP);
Serial.begin(115200);
attachInterrupt(digitalPinToInterrupt(interruptpin), interrupt, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptpin2), interrupt2, RISING);
}
void loop(){
//Serial.println("Enter data:");
if (Serial.available() != 0)
{ //wait for data available
teststr = Serial.readString(); //read until timeout
teststr.trim(); //띄어쓰기 제거
if (teststr=="one")
{
button=1;
}
else if(teststr=="two")
{
button=2;
}
else if(teststr=="three")
{
button=3;
}
else if(teststr=="zero")
{
button=0;
}
else{
}
}
if (turn_off ==1)
{
off();
//초기화해주기
button=0;
teststr="";
}
else
{
if (button%4==1)
{
button=1;
second();
}
else if(button%4==2)
{
button=2;
teststr = "";
halfsecond();
}
else if(button%4==3)
{
button=3;
teststr = "";
full();
}
else if (button%4==0)
{
button=0;
teststr = "";
off();
}
}
}
void second() //1초마다 깜빡
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
void halfsecond() //0.1초마다 깜빡
{
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
}
void full() //켜져있는 상태
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1);
}
void off(){
digitalWrite(led, LOW);
delay(1000);
}
void interrupt() //누르는 순간
{
if(millis()-cnt > 300)
{
button++;
}
cnt = millis();
}
void interrupt2() //떼는 순간
{
if(millis()-cnt > 2000)
{
if (turn_off==0)
{
turn_off=1;
}
else
{
turn_off=0;
}
}
}