-
Notifications
You must be signed in to change notification settings - Fork 0
/
MFL_complete.ino
138 lines (126 loc) · 2.83 KB
/
MFL_complete.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
136
137
138
#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, 6, NEO_GRB + NEO_KHZ800);
SoftwareSerial BTSerial(2, 3);
int redTemp = 0;
int blueTemp = 0;
int greenTemp = 0;
char modeA = 0; //초음파센서
char modeB = 0; //사운드센서
const int trigPin = 7; // Trig(송신부)를 7번으로 변수 선언
const int echoPin = 10; // Echo(수신부)를 6번으로 변수 선언
void colorWipe(uint32_t c, uint8_t wait)
{
for (uint16_t i = 0 ; i<strip.numPixels() ; i++)
{
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void controlUltrawave() {
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
long distance = (duration*340)/2/10000;
if(distance<60) {
colorWipe(strip.Color(redTemp, greenTemp, blueTemp),20);
} else {
colorWipe(strip.Color(0, 0, 0),20);
}
delay(200);
}
void controlSOS() {
for(int i=0; i<3; i++) {
colorWipe(strip.Color(255,255,255), 0);
delay(150);
colorWipe(strip.Color(0,0,0), 0);
delay(100);
}
delay(200);
for(int j=0; j<3; j++) {
colorWipe(strip.Color(255,255,255), 0);
delay(300);
colorWipe(strip.Color(0,0,0), 0);
delay(300);
}
for(int k=0; k<3; k++) {
colorWipe(strip.Color(255,255,255), 0);
delay(150);
colorWipe(strip.Color(0,0,0), 0);
delay(100);
}
delay(2000);
}
void controlSound(){
int statusSensor = analogRead(A2);
int mapping = map(statusSensor, 0, 400, 0, 23);
if(mapping == 0) {
for(int i=0; i<24; i++) {
strip.setPixelColor(i, 0, 0, 0);
strip.show();
}
} else {
for(int j=0; j< mapping; j++)
{
strip.setPixelColor(j, redTemp, greenTemp, blueTemp);
strip.show();
}
}
}
void setup()
{
BTSerial.begin(9600);
pinMode(A2, INPUT); // 사운드 센서
pinMode(5, INPUT_PULLUP);//푸시 버튼
pinMode(trigPin, OUTPUT);//7번 핀
pinMode(echoPin, INPUT);//10번 핀
strip.begin();
strip.setBrightness(255);
strip.show();
colorWipe(strip.Color(255, 0, 0),50);
colorWipe(strip.Color(0, 255, 0),50);
colorWipe(strip.Color(0, 0, 255),50);
colorWipe(strip.Color(0, 0, 0),0);
}
void loop()
{
char data;
if (BTSerial.available()) {
data= BTSerial.read();
if (BTSerial.find("r")) {
redTemp = BTSerial.parseInt();
}
if (BTSerial.find("g")) {
greenTemp = BTSerial.parseInt();
}
if (BTSerial.find("b")) {
blueTemp = BTSerial.parseInt();
colorWipe(strip.Color(redTemp, greenTemp, blueTemp),20);
}
if (data=='q') {
modeA= 1;
modeB = 0;
}
if (data=='a') {
modeA = 0;
modeB = 1;
}
if(data=='w') {
modeA = 0;
modeB = 0;
}
}
if(digitalRead(5)==LOW) {
modeA = 0;
modeB = 0;
controlSOS();
}
if(modeB == 1){
controlUltrawave();
}
if(modeA == 1){
controlSound();
}
}