質問編集履歴

2

一部修正

2021/01/27 05:07

投稿

MaeharaKenji
MaeharaKenji

スコア86

test CHANGED
File without changes
test CHANGED
@@ -220,7 +220,7 @@
220
220
 
221
221
  {
222
222
 
223
- Firebase.setInt("/M5Stack/counter02", countIncriment);
223
+ Firebase.setInt("/M5Stack/counter", countIncriment);
224
224
 
225
225
  countIncriment++;
226
226
 

1

ソースコードを追加。

2021/01/27 05:06

投稿

MaeharaKenji
MaeharaKenji

スコア86

test CHANGED
File without changes
test CHANGED
@@ -19,3 +19,221 @@
19
19
 
20
20
 
21
21
  どうぞ、ご教示の程よろしくお願い致します。
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+ ```cpp
30
+
31
+
32
+
33
+ #include <ArduinoJson.h>
34
+
35
+ #include <IOXhop_FirebaseStream.h>
36
+
37
+ #include <IOXhop_FirebaseESP32.h>
38
+
39
+ #include <M5Stack.h>
40
+
41
+ #include <WiFi.h>
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+ #define WIFI_SSID "*********"
54
+
55
+ #define WIFI_PASSWORD "*********"
56
+
57
+
58
+
59
+ // FirebaseのデータベースURL(ご自身のデータベースURLに変更してください)
60
+
61
+ #define FIREBASE_DATABASE_URL "https://*******-default-rtdb.firebaseio.com"
62
+
63
+
64
+
65
+
66
+
67
+ //timer interrupt variable.
68
+
69
+ volatile unsigned long usecCount = 0;
70
+
71
+ hw_timer_t *interrupptTimer = NULL;
72
+
73
+ portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED;
74
+
75
+
76
+
77
+ int secCount = 0;
78
+
79
+ int emgAramCount = -1;
80
+
81
+ int emgAramSoundCount = -1;
82
+
83
+
84
+
85
+
86
+
87
+ //Timer count
88
+
89
+ void IRAM_ATTR usecTimer()
90
+
91
+ {
92
+
93
+ portENTER_CRITICAL_ISR(&mutex);
94
+
95
+ usecCount += 5;
96
+
97
+ portEXIT_CRITICAL_ISR(&mutex);
98
+
99
+
100
+
101
+ if(((usecCount / 1000000) % 60) > 0){
102
+
103
+ if(secCount > -1)
104
+
105
+ {
106
+
107
+ secCount++;
108
+
109
+ }
110
+
111
+
112
+
113
+ usecCount = 0;
114
+
115
+
116
+
117
+ }
118
+
119
+ }
120
+
121
+
122
+
123
+
124
+
125
+ void setup() {
126
+
127
+ M5.begin();
128
+
129
+
130
+
131
+ // Wi-Fi接続
132
+
133
+ WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
134
+
135
+ Serial.print("connecting");
136
+
137
+ while (WiFi.status() != WL_CONNECTED) {
138
+
139
+ Serial.print(".");
140
+
141
+ delay(500);
142
+
143
+ }
144
+
145
+ Serial.println();
146
+
147
+
148
+
149
+ // Firebase初期化
150
+
151
+ Firebase.begin(FIREBASE_DATABASE_URL);
152
+
153
+
154
+
155
+ // WiFi Connected
156
+
157
+ Serial.println("\nWiFi Connected.");
158
+
159
+ Serial.println(WiFi.localIP());
160
+
161
+ M5.Lcd.setTextSize(3);
162
+
163
+ M5.Lcd.setCursor(10, 100);
164
+
165
+ M5.Lcd.println("Button Click!");
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+ //interrupt timer setting
174
+
175
+ //timerBegin is count per 100 microsec.
176
+
177
+ interrupptTimer = timerBegin(0, 80, true);
178
+
179
+
180
+
181
+ //interrupt method setting
182
+
183
+ timerAttachInterrupt(interrupptTimer, &usecTimer, true);
184
+
185
+
186
+
187
+ //interrupt timing setting.
188
+
189
+ timerAlarmWrite(interrupptTimer, 5, true);
190
+
191
+ timerAlarmDisable(interrupptTimer);
192
+
193
+
194
+
195
+ portENTER_CRITICAL(&mutex);
196
+
197
+ timerAlarmEnable(interrupptTimer);
198
+
199
+ portEXIT_CRITICAL(&mutex);
200
+
201
+ }
202
+
203
+
204
+
205
+
206
+
207
+ int countIncriment=0;
208
+
209
+
210
+
211
+ void loop() {
212
+
213
+ M5.update();
214
+
215
+
216
+
217
+
218
+
219
+ if(secCount > 0)
220
+
221
+ {
222
+
223
+ Firebase.setInt("/M5Stack/counter02", countIncriment);
224
+
225
+ countIncriment++;
226
+
227
+ secCount=0;
228
+
229
+ }
230
+
231
+
232
+
233
+ }
234
+
235
+
236
+
237
+
238
+
239
+ ```