-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBusStopBell.ino
298 lines (258 loc) · 11.2 KB
/
BusStopBell.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// --- OLED 화면출력용 라이브러리 -----------------------------------------------------
#include "U8glib.h"
#include <avr/pgmspace.h>
// -----------------------------------------------------------------------------
// --- SD카드용 라이브러리 -----------------------------------------------------------
#include <SD.h>
// -----------------------------------------------------------------------------
// --- WAV 파일 재생용 라이브러리 -----------------------------------------------------
#include <TMRpcm.h>
#include <SPI.h>
// -----------------------------------------------------------------------------
#define BTN1_PIN 3 // 버튼1 입력에 사용할 핀을 3로 설정. 아두이노 나노의 경우 RX, TX 핀은 쓰지말자.
#define BTN2_PIN 2 // 버튼2 입력에 사용할 핀을 2로 설정
#define LED_PIN 4 // LED에 사용할 핀을 4로 설정
#define SD_ChipSelectPin 10 // SD 카드와의 통신에 사용할 핀을 10으로 설정
// --- 한글 선택항목용 bmp 데이터 ------------------------------------------------
const unsigned char IMG_D1[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x06,0x60,0x00,0x00,0x00,0x60,0x00,0x00,0x3f,0x00,
0x07,0xf6,0x61,0xff,0x86,0x18,0x60,0x18,0x00,0xe1,0xc0,
0x06,0x06,0x63,0x00,0xc6,0x18,0x60,0x18,0x01,0x8c,0x60,
0x06,0x06,0x66,0x00,0x66,0x18,0x60,0x3c,0x01,0x9c,0x60,
0x06,0x06,0x66,0x00,0x66,0x18,0x60,0x7e,0x03,0x3c,0x30,
0x06,0x06,0x66,0x00,0x67,0xf8,0x60,0xe7,0x03,0x0c,0x30,
0x06,0x06,0x63,0x00,0xc6,0x1b,0xe1,0xc3,0x83,0x0c,0x30,
0x06,0x07,0xe1,0xff,0x86,0x18,0x63,0x81,0xc3,0x0c,0x30,
0x06,0x06,0x60,0x00,0x06,0x18,0x67,0x00,0xe3,0x0c,0x30,
0x06,0x06,0x67,0xff,0xe6,0x18,0x60,0x00,0x03,0x0c,0x30,
0x06,0x06,0x60,0x18,0x06,0x18,0x60,0x00,0x01,0xbf,0x60,
0x03,0xf6,0x60,0x18,0x03,0xf0,0x60,0x00,0x01,0x80,0x60,
0x00,0x06,0x60,0x18,0x00,0x00,0x67,0xff,0xe0,0xe1,0xc0,
0x00,0x06,0x60,0x18,0x00,0x00,0x60,0x00,0x00,0x3f,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
const unsigned char IMG_D2[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x06,0x60,0x00,0x00,0x00,0x60,0x00,0x00,0x3f,0x00,
0x07,0xf6,0x61,0xff,0x86,0x18,0x60,0x18,0x00,0xe1,0xc0,
0x06,0x06,0x63,0x00,0xc6,0x18,0x60,0x18,0x01,0x9e,0x60,
0x06,0x06,0x66,0x00,0x66,0x18,0x60,0x3c,0x01,0xb3,0x60,
0x06,0x06,0x66,0x00,0x66,0x18,0x60,0x7e,0x03,0x33,0x30,
0x06,0x06,0x66,0x00,0x67,0xf8,0x60,0xe7,0x03,0x03,0x30,
0x06,0x06,0x63,0x00,0xc6,0x1b,0xe1,0xc3,0x83,0x0e,0x30,
0x06,0x07,0xe1,0xff,0x86,0x18,0x63,0x81,0xc3,0x18,0x30,
0x06,0x06,0x60,0x00,0x06,0x18,0x67,0x00,0xe3,0x30,0x30,
0x06,0x06,0x67,0xff,0xe6,0x18,0x60,0x00,0x03,0x30,0x30,
0x06,0x06,0x60,0x18,0x06,0x18,0x60,0x00,0x01,0xbf,0x60,
0x03,0xf6,0x60,0x18,0x03,0xf0,0x60,0x00,0x01,0x80,0x60,
0x00,0x06,0x60,0x18,0x00,0x00,0x67,0xff,0xe0,0xe1,0xc0,
0x00,0x06,0x60,0x18,0x00,0x00,0x60,0x00,0x00,0x3f,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
const unsigned char IMG_D3[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x06,0x60,0x00,0x00,0x00,0x60,0x00,0x00,0x3f,0x00,
0x07,0xf6,0x61,0xff,0x86,0x18,0x60,0x18,0x00,0xe1,0xc0,
0x06,0x06,0x63,0x00,0xc6,0x18,0x60,0x18,0x01,0x9e,0x60,
0x06,0x06,0x66,0x00,0x66,0x18,0x60,0x3c,0x01,0xb3,0x60,
0x06,0x06,0x66,0x00,0x66,0x18,0x60,0x7e,0x03,0x33,0x30,
0x06,0x06,0x66,0x00,0x67,0xf8,0x60,0xe7,0x03,0x03,0x30,
0x06,0x06,0x63,0x00,0xc6,0x1b,0xe1,0xc3,0x83,0x0e,0x30,
0x06,0x07,0xe1,0xff,0x86,0x18,0x63,0x81,0xc3,0x03,0x30,
0x06,0x06,0x60,0x00,0x06,0x18,0x67,0x00,0xe3,0x03,0x30,
0x06,0x06,0x67,0xff,0xe6,0x18,0x60,0x00,0x03,0x33,0x30,
0x06,0x06,0x60,0x18,0x06,0x18,0x60,0x00,0x01,0xb3,0x60,
0x03,0xf6,0x60,0x18,0x03,0xf0,0x60,0x00,0x01,0x9e,0x60,
0x00,0x06,0x60,0x18,0x00,0x00,0x67,0xff,0xe0,0xe1,0xc0,
0x00,0x06,0x60,0x18,0x00,0x00,0x60,0x00,0x00,0x3f,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
const unsigned char IMG_H1[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xc0,0x60,0x06,0x60,0x00,0x60,0x00,0x00,0x3f,0x00,
0x07,0xf8,0x67,0xf6,0x66,0x18,0x60,0x18,0x00,0xe1,0xc0,
0x00,0x00,0x66,0x06,0x66,0x18,0x60,0x18,0x01,0x8c,0x60,
0x03,0xf3,0xe6,0x06,0x66,0x18,0x60,0x3c,0x01,0x9c,0x60,
0x06,0x18,0x66,0x06,0x66,0x18,0x60,0x7e,0x03,0x3c,0x30,
0x06,0x18,0x66,0x06,0x67,0xf8,0x60,0xe7,0x03,0x0c,0x30,
0x06,0x1b,0xe6,0x06,0x66,0x1b,0xe1,0xc3,0x83,0x0c,0x30,
0x06,0x18,0x66,0x07,0xe6,0x18,0x63,0x81,0xc3,0x0c,0x30,
0x03,0xf0,0x66,0x06,0x66,0x18,0x67,0x00,0xe3,0x0c,0x30,
0x00,0x00,0x66,0x06,0x66,0x18,0x60,0x00,0x03,0x0c,0x30,
0x01,0x80,0x06,0x06,0x66,0x18,0x60,0x00,0x01,0xbf,0x60,
0x01,0x80,0x03,0xf6,0x63,0xf0,0x60,0x00,0x01,0x80,0x60,
0x01,0x80,0x00,0x06,0x60,0x00,0x67,0xff,0xe0,0xe1,0xc0,
0x00,0xff,0xe0,0x06,0x60,0x00,0x60,0x00,0x00,0x3f,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
const unsigned char IMG_H2[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xc0,0x60,0x06,0x60,0x00,0x60,0x00,0x00,0x3f,0x00,
0x07,0xf8,0x67,0xf6,0x66,0x18,0x60,0x18,0x00,0xe1,0xc0,
0x00,0x00,0x66,0x06,0x66,0x18,0x60,0x18,0x01,0x9e,0x60,
0x03,0xf3,0xe6,0x06,0x66,0x18,0x60,0x3c,0x01,0xb3,0x60,
0x06,0x18,0x66,0x06,0x66,0x18,0x60,0x7e,0x03,0x33,0x30,
0x06,0x18,0x66,0x06,0x67,0xf8,0x60,0xe7,0x03,0x03,0x30,
0x06,0x1b,0xe6,0x06,0x66,0x1b,0xe1,0xc3,0x83,0x0e,0x30,
0x06,0x18,0x66,0x07,0xe6,0x18,0x63,0x81,0xc3,0x18,0x30,
0x03,0xf0,0x66,0x06,0x66,0x18,0x67,0x00,0xe3,0x30,0x30,
0x00,0x00,0x66,0x06,0x66,0x18,0x60,0x00,0x03,0x30,0x30,
0x01,0x80,0x06,0x06,0x66,0x18,0x60,0x00,0x01,0xbf,0x60,
0x01,0x80,0x03,0xf6,0x63,0xf0,0x60,0x00,0x01,0x80,0x60,
0x01,0x80,0x00,0x06,0x60,0x00,0x67,0xff,0xe0,0xe1,0xc0,
0x00,0xff,0xe0,0x06,0x60,0x00,0x60,0x00,0x00,0x3f,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
const unsigned char IMG_A[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xc1,0x80,0xc1,0x86,0x0c,0xc0,0x18,0x00,0x3c,0x40,
0x00,0xc1,0x80,0xc1,0x86,0x0c,0xc0,0x18,0x00,0x24,0x20,
0x07,0xf9,0x87,0xf9,0x86,0x0c,0xc0,0x3c,0x00,0x64,0x90,
0x00,0x01,0x80,0xc1,0x87,0xfc,0xf0,0x66,0x00,0xa4,0x48,
0x03,0xf1,0x80,0xc1,0x86,0x0c,0xc0,0xc3,0x01,0x25,0x28,
0x07,0x39,0x81,0xe1,0x86,0x0c,0xc3,0x99,0xc2,0x24,0xa4,
0x06,0x19,0xe1,0xe1,0xe6,0x0c,0xc0,0x18,0x02,0x24,0x94,
0x06,0x19,0x81,0xe1,0x83,0xf8,0xc7,0xff,0xe2,0x24,0x94,
0x06,0x19,0x83,0x31,0x80,0x00,0x00,0x00,0x02,0x24,0xa4,
0x06,0x19,0x83,0x31,0x81,0xff,0x81,0xff,0x81,0x25,0x28,
0x07,0x39,0x87,0x39,0x83,0x81,0xc3,0x81,0xc0,0xa4,0x48,
0x03,0xf1,0x86,0x19,0x83,0x00,0xc3,0x00,0xc0,0x64,0x90,
0x00,0x01,0x80,0x01,0x83,0x81,0xc3,0x81,0xc0,0x24,0x20,
0x00,0x01,0x80,0x01,0x81,0xff,0x81,0xff,0x80,0x3c,0x40,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
// --------------------------------------------------------------------------------------------------
String current; // 문자열 변수 current 선언
int currentNum = 0; // 현재 선택항목 값
int fileCountOnSD = 0; // SD 카드의 파일 갯수 세는 변수
File root;
TMRpcm tmrpcm; // TMRpcm 사용 설정
U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // u8glib 사용 선언
// --------------------------------------------------------------------------------------------------
void setup()
{
current.reserve(16); // 문자열 current를 위한 메모리 버퍼 확정. 이건 setup() 안에서 해야한다!
pinMode(BTN1_PIN, INPUT_PULLUP); // 버튼 1의 입력을 풀업저항으로 설정하여 플로팅을 없앤다
pinMode(BTN2_PIN, INPUT_PULLUP); // 버튼 2의 입력을 풀업저항으로 설정하여 플로팅을 없앤다
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println("SD fail");
return; // don't do anything more if not
}
else{
Serial.println("SD ok");
}
tmrpcm.speakerPin = 9; // 스피커용 핀 설정
tmrpcm.volume(2);
root = SD.open("/");
fileCount(root, 0);
Serial.print(F("fileCountOnSD: "));
Serial.println(fileCountOnSD);
u8g.firstPage(); // 그냥 drawChar()만 하면 안되고 이 퍼스트, 넥스트 페이지를 꼭 같이 써줘야 하는듯
do
{
current = (F("HYUNDA~1"));
u8g.drawBitmapP (1, 16, 11, 15, IMG_H1);
} while( u8g.nextPage() );
}
void loop()
{
int push1= digitalRead(BTN1_PIN); // 버튼 1이 눌리는가?
int push2 = digitalRead(BTN2_PIN); // 버튼 2가 눌리는가?
if(push1 == 0) // 버튼 1이 눌렸다면 change() 함수 실행 (선택된 파일명 변경)
{
Serial.println(F("Change!"));
change();
}
if(push2 == 0) // 버튼 2가 눌렸다면 stopSound() 함수 실행 (wav 파일 재생)
{
Serial.println(F("Sound!"));
stopSound();
}
if(tmrpcm.isPlaying() == 0)
{
tmrpcm.disable();
digitalWrite(LED_PIN, LOW);
}
}
void fileCount(File dir, int numTabs) // SD카드에 있는 파일 갯수를 알아낸다
{
while (true)
{
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
// for each file count it
fileCountOnSD++;
entry.close();
}
}
void drawChar(void) // OLED 액정에 문자 출력하는 함수
{
// 전체 화면을 다시 그리는 그래픽 명령은 반드시 여기에 넣을 것
u8g.setFont(u8g_font_9x18B);
u8g.setPrintPos(0, 20);
// 베이스 클래스에서 프로시저 호출 http://arduino.cc/en/Serial/Print
//u8g.print(current); // 현재 선택된 항목 current 값을 텍스트로 OLED에 표시
}
void change() // 버튼 입력으로 현재 선택된 사운드를 변경함
{
if(currentNum == 5)
{
currentNum = 0;
}
else
{
currentNum++;
}
u8g.firstPage();
do
{
switch (currentNum) // 버튼 누를 때마다 바뀐 값에 따라 문자열을 변경한다
{
case 0:
current = (F("HYUNDA~1"));
u8g.drawBitmapP (1, 16, 11, 15, IMG_H1);
break;
case 1:
current = (F("HYUNDA~2"));
u8g.drawBitmapP (1, 16, 11, 15, IMG_H2);
break;
case 2:
current = (F("DAEWOO_1"));
u8g.drawBitmapP (1, 16, 11, 15, IMG_D1);
break;
case 3:
current = (F("DAEWOO_2"));
u8g.drawBitmapP (1, 16, 11, 15, IMG_D2);
break;
case 4:
current = (F("DAEWOO_3"));
u8g.drawBitmapP (1, 16, 11, 15, IMG_D3);
break;
case 5:
current = (F("ANNOUNCE"));
u8g.drawBitmapP (1, 16, 11, 15, IMG_A);
break;
}
}
while(u8g.nextPage());
Serial.println(current);
delay(200);
}
void stopSound() // 파일명 current.wav 파일을 재생
{
String currentFile = current + ".wav";
// --- String currentFile을 char* 타입으로 변경함 -----------------------------------------
char currentFileName[40]={0};
currentFile.toCharArray(currentFileName,currentFile.length()+1); // 끝에 +1 안해주면 확장자 끝 한글자가 짤림
// ----------------------------------------------------------------------------------------
Serial.println(currentFileName);
digitalWrite(LED_PIN, HIGH);
tmrpcm.play(currentFileName); // 파일 재생
delay(1000);
}