Skip to content

Commit f7c45c0

Browse files
committed
init
1 parent e7e943a commit f7c45c0

28 files changed

+3384
-1
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
# pico_halfV2_arduino_examples
2-
pico_halfV2_arduino_examples
2+
Pi:Co Half V2用のArduinoサンプルスケッチ集
3+
4+
5+
## サンプルスケッチについて
6+
7+
### STEP1 ~ STEP8
8+
9+
- Pi:Co Half V2のハードウェアを動かすための、Arduinoスケッチの書き方をまとめています
10+
11+
12+
## スケッチファイルの自動整形について
13+
14+
ソースコードのレイアウトを整えるため、各スケッチファイルにはArduino IDEの自動整形を適用しています。
15+
自動整形のルールは[.clang-format](.clang-format) ファイルを参照してください。
16+
17+
## License
18+
19+
(C) 2023 RT Corporation
20+
21+
各ファイルはライセンスがファイル中に明記されている場合、そのライセンスに従います。特に明記されていない場合は、Apache License, Version 2.0に基づき公開されています。
22+
ライセンスの全文は[LICENSE](./LICENSE)または[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)から確認できます。
23+
24+
※このソフトウェアは基本的にオープンソースソフトウェアとして「AS IS」(現状有姿のまま)で提供しています。本ソフトウェアに関する無償サポートはありません。
25+
バグの修正や誤字脱字の修正に関するリクエストは常に受け付けていますが、それ以外の機能追加等のリクエストについては社内のガイドラインを優先します。
26+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2023 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+
#define LED0 42
16+
#define LED1 41
17+
#define LED2 15
18+
#define LED3 16
19+
20+
void setup()
21+
{
22+
// put your setup code here, to run once:
23+
pinMode(LED0, OUTPUT);
24+
pinMode(LED1, OUTPUT);
25+
pinMode(LED2, OUTPUT);
26+
pinMode(LED3, OUTPUT);
27+
}
28+
29+
void loop()
30+
{
31+
// put your main code here, to run repeatedly:
32+
digitalWrite(LED0, HIGH);
33+
digitalWrite(LED1, HIGH);
34+
digitalWrite(LED2, HIGH);
35+
digitalWrite(LED3, HIGH);
36+
delay(500);
37+
digitalWrite(LED0, LOW);
38+
digitalWrite(LED1, LOW);
39+
digitalWrite(LED2, LOW);
40+
digitalWrite(LED3, LOW);
41+
delay(500);
42+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2023 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+
#define LED0 42
16+
#define LED1 41
17+
#define LED2 15
18+
#define LED3 16
19+
20+
#define SW_C 13
21+
#define SW_R 14
22+
23+
int g_state_r, g_state_c;
24+
25+
void setup()
26+
{
27+
// put your setup code here, to run once:
28+
pinMode(LED0, OUTPUT);
29+
pinMode(LED1, OUTPUT);
30+
pinMode(LED2, OUTPUT);
31+
pinMode(LED3, OUTPUT);
32+
33+
pinMode(SW_C, INPUT);
34+
pinMode(SW_R, INPUT);
35+
36+
g_state_r = g_state_c = 0;
37+
}
38+
39+
void loop()
40+
{
41+
// put your main code here, to run repeatedly:
42+
while ( digitalRead(SW_C) && digitalRead(SW_R)) {
43+
continue;
44+
}
45+
if (digitalRead(SW_R) == 0) {
46+
digitalWrite(LED3, (++g_state_r) & 0x01);
47+
}
48+
if (digitalRead(SW_C) == 0) {
49+
digitalWrite(LED2, (++g_state_c) & 0x01);
50+
digitalWrite(LED1, (g_state_c)&0x01);
51+
}
52+
delay(30);
53+
while (!(digitalRead(SW_C) && digitalRead(SW_R))) {
54+
continue;
55+
}
56+
delay(30);
57+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Copyright 2023 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+
#define LED0 42
16+
#define LED1 41
17+
#define LED2 15
18+
#define LED3 16
19+
20+
#define SW_C 13
21+
#define SW_R 14
22+
23+
#define BUZZER 40
24+
25+
#define INC_FREQ 2000
26+
#define DEC_FREQ 1000
27+
28+
#define FREQ_C 523 //
29+
#define FREQ_D 587 //
30+
#define FREQ_E 659 //
31+
32+
char g_mode;
33+
34+
void setLED(char data)
35+
{
36+
if (data & 0x01) {
37+
digitalWrite(LED0, HIGH);
38+
} else {
39+
digitalWrite(LED0, LOW);
40+
}
41+
if (data & 0x02) {
42+
digitalWrite(LED1, HIGH);
43+
} else {
44+
digitalWrite(LED1, LOW);
45+
}
46+
if (data & 0x04) {
47+
digitalWrite(LED2, HIGH);
48+
} else {
49+
digitalWrite(LED2, LOW);
50+
}
51+
if (data & 0x08) {
52+
digitalWrite(LED3, HIGH);
53+
} else {
54+
digitalWrite(LED3, LOW);
55+
}
56+
}
57+
58+
void execByMode(char mode)
59+
{
60+
switch (mode) {
61+
case 1:
62+
ledcWriteTone(0, FREQ_C);
63+
delay(1000);
64+
ledcWrite(0, 1024);
65+
break;
66+
case 2:
67+
ledcWriteTone(0, FREQ_D);
68+
delay(1000);
69+
ledcWrite(0, 1024);
70+
break;
71+
case 3:
72+
ledcWriteTone(0, FREQ_E);
73+
delay(1000);
74+
ledcWrite(0, 1024);
75+
break;
76+
default:
77+
ledcWrite(0, 1024);
78+
break;
79+
}
80+
}
81+
82+
void setup()
83+
{
84+
// put your setup code here, to run once:
85+
pinMode(LED0, OUTPUT);
86+
pinMode(LED1, OUTPUT);
87+
pinMode(LED2, OUTPUT);
88+
pinMode(LED3, OUTPUT);
89+
90+
pinMode(SW_C, INPUT);
91+
pinMode(SW_R, INPUT);
92+
93+
ledcSetup(0, 440, 10);
94+
ledcAttachPin(BUZZER, 0);
95+
ledcWrite(0, 1024);
96+
97+
g_mode = 1;
98+
setLED(g_mode);
99+
}
100+
101+
void loop()
102+
{
103+
// put your main code here, to run repeatedly:
104+
while ( digitalRead(SW_C) & digitalRead(SW_R)) {
105+
continue;
106+
}
107+
if (digitalRead(SW_R) == 0) {
108+
g_mode++;
109+
if (g_mode > 15) {
110+
g_mode = 1;
111+
} else {
112+
ledcWriteTone(0, INC_FREQ);
113+
delay(30);
114+
ledcWrite(0, 1024);
115+
}
116+
setLED(g_mode);
117+
}
118+
if (digitalRead(SW_C) == 0) {
119+
ledcWriteTone(0, INC_FREQ);
120+
delay(80);
121+
ledcWriteTone(0, DEC_FREQ);
122+
delay(80);
123+
ledcWrite(0, 1024);
124+
delay(300);
125+
execByMode(g_mode);
126+
}
127+
while (!(digitalRead(SW_C) & digitalRead(SW_R))) {
128+
continue;
129+
}
130+
delay(30);
131+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright 2023 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+
#define SLED_F 2
16+
#define SLED_S 1
17+
18+
#define AD4 5
19+
#define AD3 4
20+
#define AD2 7
21+
#define AD1 6
22+
#define AD0 8
23+
24+
volatile short g_sensor_value_fr;
25+
volatile short g_sensor_value_fl;
26+
volatile short g_sensor_value_r;
27+
volatile short g_sensor_value_l;
28+
volatile short g_battery_value;
29+
30+
hw_timer_t * g_timer1 = NULL;
31+
portMUX_TYPE g_timer_mux = portMUX_INITIALIZER_UNLOCKED;
32+
33+
void IRAM_ATTR onTimer1(void)
34+
{
35+
static char cnt = 0;
36+
short temp_r,temp_l;
37+
portENTER_CRITICAL_ISR(&g_timer_mux);
38+
switch (cnt) {
39+
case 0:
40+
temp_r = analogRead(AD4);
41+
temp_l = analogRead(AD1);
42+
43+
digitalWrite(SLED_F, HIGH); //LED点灯
44+
for (int i = 0; i < 10; i++) {
45+
asm("nop \n");
46+
}
47+
g_sensor_value_fr = analogRead(AD4) - temp_r;
48+
g_sensor_value_fl = analogRead(AD1) - temp_l;
49+
digitalWrite(SLED_F, LOW); //LED消灯
50+
break;
51+
case 1:
52+
temp_r = analogRead(AD3);
53+
temp_l = analogRead(AD2);
54+
55+
digitalWrite(SLED_S, HIGH); //LED点灯
56+
for (int i = 0; i < 10; i++) {
57+
asm("nop \n");
58+
}
59+
g_sensor_value_r = analogRead(AD3) - temp_r;
60+
g_sensor_value_l = analogRead(AD2) - temp_l;
61+
digitalWrite(SLED_S, LOW); //LED消灯
62+
g_battery_value = (double)analogReadMilliVolts(AD0) / 1.0 * (1.0 + 10.0);
63+
break;
64+
default:
65+
Serial.printf("error¥n¥r");
66+
break;
67+
}
68+
cnt++;
69+
if (cnt == 2) cnt = 0;
70+
portEXIT_CRITICAL_ISR(&g_timer_mux);
71+
}
72+
73+
void setup()
74+
{
75+
// put your setup code here, to run once:
76+
//Sensor 発光off
77+
pinMode(SLED_F, OUTPUT);
78+
pinMode(SLED_S, OUTPUT);
79+
digitalWrite(SLED_F, LOW);
80+
digitalWrite(SLED_S, LOW);
81+
82+
Serial.begin(115200);
83+
84+
g_timer1 = timerBegin(1, 80, true); //1us
85+
timerAttachInterrupt(g_timer1, &onTimer1, true);
86+
timerAlarmWrite(g_timer1, 500, true); //2kHz
87+
timerAlarmEnable(g_timer1);
88+
}
89+
90+
void loop()
91+
{
92+
// put your main code here, to run repeatedly:
93+
Serial.printf("r_sen is %d\n\r", g_sensor_value_r);
94+
Serial.printf("fr_sen is %d\n\r", g_sensor_value_fr);
95+
Serial.printf("fl_sen is %d\n\r", g_sensor_value_fl);
96+
Serial.printf("l_sen is %d\n\r", g_sensor_value_l);
97+
Serial.printf("VDD is %d\n\r", g_battery_value);
98+
delay(100);
99+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2023 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+
void controlInterrupt(void)
16+
{
17+
g_speed += g_accel;
18+
19+
if (g_speed > g_max_speed) {
20+
g_speed = g_max_speed;
21+
}
22+
if (g_speed < g_min_speed) {
23+
g_speed = g_min_speed;
24+
}
25+
26+
g_step_hz_l = g_step_hz_r = (unsigned short)(g_speed / PULSE);
27+
}

0 commit comments

Comments
 (0)