Skip to content

Commit ed4c968

Browse files
committed
init
1 parent e64174b commit ed4c968

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5336
-0
lines changed

.DS_Store

10 KB
Binary file not shown.

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# pico_classic4_arduino_examples
2+
![pico_classic4](images/PiCo_Classic4_image.jpg)
3+
4+
Pi:Co Classic4用 Arduino サンプルスケッチ集です。
5+
6+
## 動作環境
7+
- Arduino IDE v2.3.4
8+
- Arduino-ESP32 v3.1.3
9+
- Async TCP 3.3.6
10+
- ESP Async WebServer 3.7.1
11+
12+
## サンプルプログラムについて
13+
### STEP1 〜 STEP8
14+
15+
- Pi:Co Classic4のハードウェアを動かすための、Arduinoスケッチの書き方をまとめています
16+
17+
## スケッチファイルの自動整形について
18+
- ソースコードのレイアウトを整えるため、各スケッチファイルにはArduino IDEの自動整形を適用しています。 自動整形のルールは[.clang-format](.clang-format) ファイルを参照してください。
19+
20+
21+
## License
22+
23+
(C) 2025 RT Corporation
24+
25+
各ファイルはライセンスがファイル中に明記されている場合、そのライセンスに従います。特に明記されていない場合は、Apache License, Version 2.0に基づき公開されています。
26+
ライセンスの全文は[LICENSE](./LICENSE)または[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)から確認できます。
27+
28+
※このソフトウェアは基本的にオープンソースソフトウェアとして「AS IS」(現状有姿のまま)で提供しています。本ソフトウェアに関する無償サポートはありません。
29+
バグの修正や誤字脱字の修正に関するリクエストは常に受け付けていますが、それ以外の機能追加等のリクエストについては社内のガイドラインを優先します。

images/PiCo_Classic4_image.jpg

286 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2025 RT Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
#define LED0 13
17+
#define LED1 14
18+
#define LED2 47
19+
#define LED3 48
20+
21+
void setup()
22+
{
23+
// put your setup code here, to run once:
24+
pinMode(LED0, OUTPUT);
25+
pinMode(LED1, OUTPUT);
26+
pinMode(LED2, OUTPUT);
27+
pinMode(LED3, OUTPUT);
28+
}
29+
30+
void loop()
31+
{
32+
// put your main code here, to run repeatedly:
33+
digitalWrite(LED0, HIGH);
34+
digitalWrite(LED1, HIGH);
35+
digitalWrite(LED2, HIGH);
36+
digitalWrite(LED3, HIGH);
37+
delay(500);
38+
digitalWrite(LED0, LOW);
39+
digitalWrite(LED1, LOW);
40+
digitalWrite(LED2, LOW);
41+
digitalWrite(LED3, LOW);
42+
delay(500);
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2025 RT Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
#define LED0 13
17+
#define LED1 14
18+
#define LED2 47
19+
#define LED3 48
20+
21+
#define SW_L 16
22+
#define SW_C 15
23+
#define SW_R 18
24+
25+
int g_state_r, g_state_c, g_state_l;
26+
27+
void setup()
28+
{
29+
// put your setup code here, to run once:
30+
pinMode(LED0, OUTPUT);
31+
pinMode(LED1, OUTPUT);
32+
pinMode(LED2, OUTPUT);
33+
pinMode(LED3, OUTPUT);
34+
35+
pinMode(SW_L, INPUT_PULLUP);
36+
pinMode(SW_C, INPUT_PULLUP);
37+
pinMode(SW_R, INPUT_PULLUP);
38+
39+
g_state_r = g_state_c = g_state_l = 0;
40+
41+
}
42+
43+
void loop()
44+
{
45+
// put your main code here, to run repeatedly:
46+
while (digitalRead(SW_L) && digitalRead(SW_C) && digitalRead(SW_R)) {
47+
continue;
48+
}
49+
if (digitalRead(SW_R) == 0) {
50+
digitalWrite(LED0, (++g_state_r) & 0x01);
51+
}
52+
if (digitalRead(SW_C) == 0) {
53+
digitalWrite(LED1, (++g_state_c) & 0x01);
54+
digitalWrite(LED2, (g_state_c)&0x01);
55+
}
56+
if (digitalRead(SW_L) == 0) {
57+
digitalWrite(LED3, (++g_state_l) & 0x01);
58+
}
59+
delay(30);
60+
while (!(digitalRead(SW_L) && digitalRead(SW_C) && digitalRead(SW_R))) {
61+
continue;
62+
}
63+
delay(30);
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// Copyright 2025 RT Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
#define LED0 13
17+
#define LED1 14
18+
#define LED2 47
19+
#define LED3 48
20+
21+
#define SW_L 16
22+
#define SW_C 15
23+
#define SW_R 18
24+
25+
#define BUZZER 38
26+
27+
#define INC_FREQ 2000
28+
#define DEC_FREQ 1000
29+
30+
#define FREQ_C 523 //
31+
#define FREQ_D 587 //
32+
#define FREQ_E 659 //
33+
34+
char g_mode;
35+
36+
void ledSet(char data)
37+
{
38+
if (data & 0x01) {
39+
digitalWrite(LED0, HIGH);
40+
} else {
41+
digitalWrite(LED0, LOW);
42+
}
43+
if (data & 0x02) {
44+
digitalWrite(LED1, HIGH);
45+
} else {
46+
digitalWrite(LED1, LOW);
47+
}
48+
if (data & 0x04) {
49+
digitalWrite(LED2, HIGH);
50+
} else {
51+
digitalWrite(LED2, LOW);
52+
}
53+
if (data & 0x08) {
54+
digitalWrite(LED3, HIGH);
55+
} else {
56+
digitalWrite(LED3, LOW);
57+
}
58+
}
59+
60+
void modeExec(char mode)
61+
{
62+
switch (mode) {
63+
case 1:
64+
ledcWriteTone(BUZZER, FREQ_C);
65+
delay(1000);
66+
ledcWrite(BUZZER, 1024);
67+
break;
68+
case 2:
69+
ledcWriteTone(BUZZER, FREQ_D);
70+
delay(1000);
71+
ledcWrite(BUZZER, 1024);
72+
break;
73+
case 3:
74+
ledcWriteTone(BUZZER, FREQ_E);
75+
delay(1000);
76+
ledcWrite(BUZZER, 1024);
77+
break;
78+
default:
79+
ledcWrite(BUZZER, 1024);
80+
break;
81+
}
82+
}
83+
84+
void setup()
85+
{
86+
// put your setup code here, to run once:
87+
pinMode(LED0, OUTPUT);
88+
pinMode(LED1, OUTPUT);
89+
pinMode(LED2, OUTPUT);
90+
pinMode(LED3, OUTPUT);
91+
92+
pinMode(SW_L, INPUT_PULLUP);
93+
pinMode(SW_C, INPUT_PULLUP);
94+
pinMode(SW_R, INPUT_PULLUP);
95+
96+
ledcAttach(BUZZER, 440, 10);
97+
ledcWrite(BUZZER, 1024);
98+
99+
g_mode = 1;
100+
ledSet(g_mode);
101+
}
102+
103+
void loop()
104+
{
105+
// put your main code here, to run repeatedly:
106+
while (digitalRead(SW_L) & digitalRead(SW_C) & digitalRead(SW_R)) {
107+
continue;
108+
}
109+
if (digitalRead(SW_R) == 0) {
110+
g_mode++;
111+
if (g_mode > 15) {
112+
g_mode = 15;
113+
} else {
114+
ledcWriteTone(BUZZER, INC_FREQ);
115+
delay(30);
116+
ledcWrite(BUZZER, 1024);
117+
}
118+
ledSet(g_mode);
119+
}
120+
if (digitalRead(SW_L) == 0) {
121+
g_mode--;
122+
if (g_mode < 1) {
123+
g_mode = 1;
124+
} else {
125+
ledcWriteTone(BUZZER, DEC_FREQ);
126+
delay(30);
127+
ledcWrite(BUZZER, 1024);
128+
}
129+
ledSet(g_mode);
130+
}
131+
if (digitalRead(SW_C) == 0) {
132+
ledcWriteTone(BUZZER, INC_FREQ);
133+
delay(80);
134+
ledcWriteTone(BUZZER, DEC_FREQ);
135+
delay(80);
136+
ledcWrite(BUZZER, 1024);
137+
delay(300);
138+
modeExec(g_mode);
139+
}
140+
while (!(digitalRead(SW_L) & digitalRead(SW_C) & digitalRead(SW_R))) {
141+
continue;
142+
}
143+
delay(30);
144+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2025 RT Corporation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
#define SLED_FR 9
17+
#define SLED_FL 10
18+
#define SLED_R 11
19+
#define SLED_L 12
20+
21+
#define AD4 7
22+
#define AD3 6
23+
#define AD2 5
24+
#define AD1 4
25+
#define AD0 8
26+
27+
volatile short g_sensor_value_fr;
28+
volatile short g_sensor_value_fl;
29+
volatile short g_sensor_value_r;
30+
volatile short g_sensor_value_l;
31+
volatile short g_battery_value;
32+
33+
hw_timer_t* g_timer1 = NULL;
34+
portMUX_TYPE g_timer_mux = portMUX_INITIALIZER_UNLOCKED;
35+
36+
void IRAM_ATTR onTimer1(void) {
37+
static char cnt = 0;
38+
portENTER_CRITICAL_ISR(&g_timer_mux);
39+
switch (cnt) {
40+
case 0:
41+
digitalWrite(SLED_FR, HIGH); //LED点灯
42+
for (int i = 0; i < 300; i++) {
43+
asm("nop \n");
44+
}
45+
g_sensor_value_fr = analogRead(AD1);
46+
digitalWrite(SLED_FR, LOW); //LED消灯
47+
break;
48+
case 1:
49+
digitalWrite(SLED_FL, HIGH); //LED点灯
50+
for (int i = 0; i < 300; i++) {
51+
asm("nop \n");
52+
}
53+
g_sensor_value_fl = analogRead(AD2);
54+
digitalWrite(SLED_FL, LOW); //LED消灯
55+
break;
56+
case 2:
57+
digitalWrite(SLED_R, HIGH); //LED点灯
58+
for (int i = 0; i < 300; i++) {
59+
asm("nop \n");
60+
}
61+
g_sensor_value_r = analogRead(AD3);
62+
digitalWrite(SLED_R, LOW); //LED消灯
63+
break;
64+
case 3:
65+
digitalWrite(SLED_L, HIGH); //LED点灯
66+
for (int i = 0; i < 300; i++) {
67+
asm("nop \n");
68+
}
69+
g_sensor_value_l = analogRead(AD4);
70+
digitalWrite(SLED_L, LOW); //LED消灯
71+
g_battery_value = (double)analogReadMilliVolts(AD0) / 10.0 * (10.0 + 51.0);
72+
break;
73+
default:
74+
Serial.printf("error¥n¥r");
75+
break;
76+
}
77+
cnt++;
78+
if (cnt >= 4) cnt = 0;
79+
portEXIT_CRITICAL_ISR(&g_timer_mux);
80+
}
81+
82+
void setup() {
83+
// put your setup code here, to run once:
84+
//Sensor 発光off
85+
pinMode(SLED_FR, OUTPUT);
86+
pinMode(SLED_FL, OUTPUT);
87+
pinMode(SLED_R, OUTPUT);
88+
pinMode(SLED_L, OUTPUT);
89+
digitalWrite(SLED_FR, LOW);
90+
digitalWrite(SLED_FL, LOW);
91+
digitalWrite(SLED_R, LOW);
92+
digitalWrite(SLED_L, LOW);
93+
94+
Serial.begin(115200);
95+
96+
g_timer1 = timerBegin(1000000); //1MHz(1us)
97+
timerAttachInterrupt(g_timer1, &onTimer1);
98+
timerAlarm(g_timer1, 250, true, 0); //250 * 1us =250us(4kHz)
99+
timerStart(g_timer1);
100+
}
101+
102+
void loop() {
103+
// put your main code here, to run repeatedly:
104+
Serial.printf("r_sen is %d\n\r", g_sensor_value_r);
105+
Serial.printf("fr_sen is %d\n\r", g_sensor_value_fr);
106+
Serial.printf("fl_sen is %d\n\r", g_sensor_value_fl);
107+
Serial.printf("l_sen is %d\n\r", g_sensor_value_l);
108+
Serial.printf("VDD is %d\n\r", g_battery_value);
109+
delay(100);
110+
}

0 commit comments

Comments
 (0)