質問編集履歴
1
自動整形を適応
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,320 +8,292 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
/* Arduino Based - 7Seg Display Clock (4 Digits HH : MM)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
//Library
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
D
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
//
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
const int s
|
48
|
-
|
49
|
-
const int
|
50
|
-
|
51
|
-
const int
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
//
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
i
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
int n
|
64
|
-
|
65
|
-
in
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
int
|
70
|
-
|
71
|
-
in
|
72
|
-
|
73
|
-
int
|
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
|
-
void loop()
|
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
|
-
|
11
|
+
"/* Arduino Based - 7Seg Display Clock (4 Digits HH : MM)
|
12
|
+
|
13
|
+
Can be activated via sound through the microphone
|
14
|
+
|
15
|
+
Dev: Michalis Vasilakis // Date: 30/12/2015 // License: BY-NC-SA
|
16
|
+
|
17
|
+
More info soon at www.ardumotive.com
|
18
|
+
|
19
|
+
//Library
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
include "SevenSeg.h"
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
include <DS1302.h>
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
//Seven Seg and DS1302 init
|
32
|
+
|
33
|
+
SevenSeg disp (11,12,8,7,6,10,9); //Defines the segments A-G: SevenSeg(A, B, C, D, E, F, G);
|
34
|
+
|
35
|
+
const int numOfDigits =4; //Number of 7 segments
|
36
|
+
|
37
|
+
int digitPins [numOfDigits]={3,4,5,13}; //CC(or CA) pins of segment
|
38
|
+
|
39
|
+
DS1302 rtc(0,1,2); // Init the DS1302
|
40
|
+
|
41
|
+
Time t; // Init a Time-data structure
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
//Constants
|
46
|
+
|
47
|
+
const int selectBT = A0; //Select - Set button at pin A0
|
48
|
+
|
49
|
+
const int changeBT = A1; //Change button at pin A1
|
50
|
+
|
51
|
+
const int showBT = A2; //Show time button at pin A2
|
52
|
+
|
53
|
+
const int mic = A3; //Microphone at pin A3
|
54
|
+
|
55
|
+
const int leds= A4; //Leds to seperate time from min HH : MM
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
//Variables
|
60
|
+
|
61
|
+
int hour;
|
62
|
+
|
63
|
+
int min;
|
64
|
+
|
65
|
+
String clock;
|
66
|
+
|
67
|
+
int number;
|
68
|
+
|
69
|
+
int count=0;
|
70
|
+
|
71
|
+
unsigned long cc=0;
|
72
|
+
|
73
|
+
int sound;
|
74
|
+
|
75
|
+
int flag=0;
|
76
|
+
|
77
|
+
int flag1=0;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
void setup() {
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
//Define Pins as inputs or outputs:
|
86
|
+
|
87
|
+
pinMode(selectBT, INPUT_PULLUP);
|
88
|
+
|
89
|
+
pinMode(changeBT, INPUT_PULLUP);
|
90
|
+
|
91
|
+
pinMode(showBT, INPUT_PULLUP);
|
92
|
+
|
93
|
+
pinMode(min, INPUT);
|
94
|
+
|
95
|
+
pinMode(leds, OUTPUT);
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
// Set the clock to run-mode, and disable the write protection
|
100
|
+
|
101
|
+
rtc.halt(false);
|
102
|
+
|
103
|
+
rtc.writeProtect(false);
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
//Defines the number of digits to be "numOfDigits" and the digit pins to be the elements of the array "digitPins"
|
108
|
+
|
109
|
+
disp.setDigitPins ( numOfDigits , digitPins );
|
110
|
+
|
111
|
+
//Only for common cathode 7segments
|
112
|
+
|
113
|
+
disp.setCommonCathode();
|
114
|
+
|
115
|
+
//Control brightness (values 0-100);
|
116
|
+
|
117
|
+
disp.setDutyCycle(70);
|
118
|
+
|
119
|
+
disp.setTimer (2);
|
120
|
+
|
121
|
+
disp.startTimer ();
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
void loop()
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
sound = analogRead(mic);
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
if ((hour<=9) && (min>9)){
|
138
|
+
|
139
|
+
clock = '0' + String(hour) + String(min);
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
else if ((min<=9) && (hour>9)){
|
146
|
+
|
147
|
+
clock = String(hour) + '0' + String(min);
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
else if ((hour<=9) && (min<=9)){
|
152
|
+
|
153
|
+
clock = '0' + String(hour) + '0' + String(min);
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
else{
|
158
|
+
|
159
|
+
clock = String(hour) + String(min);
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
number = clock.toInt();
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
if (digitalRead(selectBT) == LOW){
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
delay(300);
|
174
|
+
|
175
|
+
count++;
|
176
|
+
|
177
|
+
if (count>2){
|
178
|
+
|
179
|
+
count=0;
|
180
|
+
|
181
|
+
rtc.setTime(hour, min, 0); // Set the hour to 12:00:00 (24hr format)
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
if (count>0){
|
190
|
+
|
191
|
+
if (digitalRead(changeBT) == LOW){
|
192
|
+
|
193
|
+
delay(300);
|
194
|
+
|
195
|
+
if (count == 1){
|
196
|
+
|
197
|
+
if (hour>22){
|
198
|
+
|
199
|
+
hour=0;
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
else{
|
204
|
+
|
205
|
+
hour++;
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
if (count == 2){
|
212
|
+
|
213
|
+
if (min>58){
|
214
|
+
|
215
|
+
min=0;
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
else{
|
220
|
+
|
221
|
+
min++;
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
else{
|
232
|
+
|
233
|
+
// Get data from the DS1302
|
234
|
+
|
235
|
+
t = rtc.getTime();
|
236
|
+
|
237
|
+
hour = t.hour;
|
238
|
+
|
239
|
+
min = t.min;
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
if ((digitalRead(showBT) == LOW) || (sound<445 || sound>485)){
|
244
|
+
|
245
|
+
delay(500);
|
246
|
+
|
247
|
+
//...ones, turn led on!
|
248
|
+
|
249
|
+
if ( flag == 0){
|
250
|
+
|
251
|
+
digitalWrite(leds, HIGH);
|
252
|
+
|
253
|
+
flag=1; //change flag variable
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
//...twice, turn led off!
|
258
|
+
|
259
|
+
else if ( flag == 1){
|
260
|
+
|
261
|
+
flag=0; //change flag variable again
|
262
|
+
|
263
|
+
digitalWrite(leds, LOW);
|
264
|
+
|
265
|
+
hideTime();
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
if (flag == 1){
|
272
|
+
|
273
|
+
showTime();
|
274
|
+
|
275
|
+
}
|
240
276
|
|
241
277
|
else{
|
242
278
|
|
243
|
-
// Get data from the DS1302
|
244
|
-
|
245
|
-
t = rtc.getTime();
|
246
|
-
|
247
|
-
hour = t.hour;
|
248
|
-
|
249
|
-
min = t.min;
|
250
|
-
|
251
|
-
}
|
279
|
+
}
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
280
|
+
|
258
|
-
|
259
|
-
delay(500);
|
260
|
-
|
261
|
-
//...ones, turn led on!
|
262
|
-
|
263
|
-
if ( flag == 0){
|
264
|
-
|
265
|
-
digitalWrite(leds, HIGH);
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
flag=1; //change flag variable
|
270
|
-
|
271
|
-
|
281
|
+
}
|
272
|
-
|
273
|
-
|
282
|
+
|
274
|
-
|
275
|
-
else if ( flag == 1){
|
276
|
-
|
277
|
-
flag=0; //change flag variable again
|
278
|
-
|
279
|
-
digitalWrite(leds, LOW);
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
283
|
+
void showTime(){
|
284
|
+
|
284
|
-
|
285
|
+
disp.write(clock);
|
286
|
+
|
285
|
-
|
287
|
+
}
|
288
|
+
|
286
|
-
|
289
|
+
void hideTime(){
|
290
|
+
|
291
|
+
disp.write(" ");
|
292
|
+
|
287
|
-
|
293
|
+
}
|
288
|
-
|
289
|
-
|
294
|
+
|
290
|
-
|
291
|
-
showTime();
|
292
|
-
|
293
|
-
}
|
294
|
-
|
295
|
-
else{
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
void showTime(){
|
308
|
-
|
309
|
-
disp.write(clock);
|
310
|
-
|
311
|
-
}
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
void hideTime(){
|
316
|
-
|
317
|
-
disp.write(" ");
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
ISR( TIMER2_COMPA_vect ){
|
295
|
+
ISR( TIMER2_COMPA_vect ){
|
324
|
-
|
296
|
+
|
325
|
-
disp.interruptAction ();
|
297
|
+
disp.interruptAction ();
|
326
|
-
|
298
|
+
|
327
|
-
}
|
299
|
+
}"
|