Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ci for v3.0 #7

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/compile-sketches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
platforms: | # ESP32公式のpackage indexを使用する
- name: esp32:esp32
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
version: 2.0.17
version: 3.0.1
sketch-paths: |
- pico_v2_STEP1_LED
- pico_v2_STEP2_SWITCH
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ Pi:Co V2用のArduinoサンプルスケッチ集

## 動作環境

- arduino-esp32 : v2.0.17
- arduino-esp32 : v3.0.1

## サンプルスケッチについて

### STEP1 ~ STEP8

- Pi:Co V2のハードウェアを動かすための、Arduinoスケッチの書き方をまとめています


## スケッチファイルの自動整形について

ソースコードのレイアウトを整えるため、各スケッチファイルにはArduino IDEの自動整形を適用しています。
Expand Down
Binary file added pico_v2_STEP3_Buzzer/.DS_Store
Binary file not shown.
29 changes: 14 additions & 15 deletions pico_v2_STEP3_Buzzer/pico_v2_STEP3_Buzzer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ void execByMode(char mode)
{
switch (mode) {
case 1:
ledcWriteTone(0, FREQ_C);
ledcWriteTone(BUZZER, FREQ_C);
delay(1000);
ledcWrite(0, 1024);
ledcWrite(BUZZER, 0);
break;
case 2:
ledcWriteTone(0, FREQ_D);
ledcWriteTone(BUZZER, FREQ_D);
delay(1000);
ledcWrite(0, 1024);
ledcWrite(BUZZER, 0);
break;
case 3:
ledcWriteTone(0, FREQ_E);
ledcWriteTone(BUZZER, FREQ_E);
delay(1000);
ledcWrite(0, 1024);
ledcWrite(BUZZER, 0);
break;
default:
ledcWrite(0, 1024);
ledcWrite(BUZZER, 0);
break;
}
}
Expand All @@ -90,9 +90,8 @@ void setup()
pinMode(SW_L, INPUT);
pinMode(SW_R, INPUT);

ledcSetup(0, 440, 10);
ledcAttachPin(BUZZER, 0);
ledcWrite(0, 1024);
ledcAttach(BUZZER, 440, 10);
ledcWrite(BUZZER, 0);

g_mode = 1;
setLED(g_mode);
Expand All @@ -109,18 +108,18 @@ void loop()
if (g_mode > 15) {
g_mode = 1;
} else {
ledcWriteTone(0, INC_FREQ);
ledcWriteTone(BUZZER, INC_FREQ);
delay(30);
ledcWrite(0, 1024);
ledcWrite(BUZZER, 0);
}
setLED(g_mode);
}
if (digitalRead(SW_L) == 0) {
ledcWriteTone(0, INC_FREQ);
ledcWriteTone(BUZZER, INC_FREQ);
delay(80);
ledcWriteTone(0, DEC_FREQ);
ledcWriteTone(BUZZER, DEC_FREQ);
delay(80);
ledcWrite(0, 1024);
ledcWrite(BUZZER, 0);
delay(300);
execByMode(g_mode);
}
Expand Down
Binary file added pico_v2_STEP4_Sensor/.DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions pico_v2_STEP4_Sensor/pico_v2_STEP4_Sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ void setup()

Serial.begin(115200);

g_timer1 = timerBegin(1, 80, true); //1us
timerAttachInterrupt(g_timer1, &onTimer1, true);
timerAlarmWrite(g_timer1, 500, true); //2kHz
timerAlarmEnable(g_timer1);
g_timer1 = timerBegin(1000000); //1us
timerAttachInterrupt(g_timer1, &onTimer1);
timerAlarm(g_timer1, 500, true, 0); //2kHz
timerStart(g_timer1);
}

void loop()
Expand Down
Binary file added pico_v2_STEP5_Straight/.DS_Store
Binary file not shown.
28 changes: 14 additions & 14 deletions pico_v2_STEP5_Straight/pico_v2_STEP5_Straight.ino
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void IRAM_ATTR isrR(void)
{
portENTER_CRITICAL_ISR(&g_timer_mux); //割り込み禁止
if (g_motor_move) {
timerAlarmWrite(g_timer2, 2000000 / g_step_hz_r, true);
timerAlarm(g_timer2, 2000000 / g_step_hz_r, true, 0);
digitalWrite(PWM_R, HIGH);
for (int i = 0; i < 100; i++) {
asm("nop \n");
Expand All @@ -78,7 +78,7 @@ void IRAM_ATTR isrL(void)
{
portENTER_CRITICAL_ISR(&g_timer_mux); //割り込み禁止
if (g_motor_move) {
timerAlarmWrite(g_timer3, 2000000 / g_step_hz_l, true);
timerAlarm(g_timer3, 2000000 / g_step_hz_l, true, 0);
digitalWrite(PWM_L, HIGH);
for (int i = 0; i < 100; i++) {
asm("nop \n");
Expand Down Expand Up @@ -113,20 +113,20 @@ void setup()
digitalWrite(PWM_R, LOW);
digitalWrite(PWM_L, LOW);

g_timer0 = timerBegin(0, 80, true); //1us
timerAttachInterrupt(g_timer0, &onTimer0, true);
timerAlarmWrite(g_timer0, 1000, true); //1kHz
timerAlarmEnable(g_timer0);
g_timer0 = timerBegin(1000000); //1us
timerAttachInterrupt(g_timer0, &onTimer0);
timerAlarm(g_timer0, 1000, true, 0); //1kHz
timerStart(g_timer0);

g_timer2 = timerBegin(2, 40, true); //0.5us
timerAttachInterrupt(g_timer2, isrR, true);
timerAlarmWrite(g_timer2, 13333, true); //150Hz
timerAlarmEnable(g_timer2);
g_timer2 = timerBegin(2000000); //0.5us
timerAttachInterrupt(g_timer2, isrR);
timerAlarm(g_timer2, 13333, true, 0); //150Hz
timerStart(g_timer2);

g_timer3 = timerBegin(3, 40, true); //0.5us
timerAttachInterrupt(g_timer3, &isrL, true);
timerAlarmWrite(g_timer3, 13333, true); //150Hz
timerAlarmEnable(g_timer3);
g_timer3 = timerBegin(2000000); //0.5us
timerAttachInterrupt(g_timer3, &isrL);
timerAlarm(g_timer3, 13333, true, 0); //150Hz
timerStart(g_timer3);
}

void loop()
Expand Down
Binary file added pico_v2_STEP6_rotate/.DS_Store
Binary file not shown.
28 changes: 14 additions & 14 deletions pico_v2_STEP6_rotate/pico_v2_STEP6_rotate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void IRAM_ATTR isrR(void)
{
portENTER_CRITICAL_ISR(&g_timer_mux); //割り込み禁止
if (g_motor_move) {
timerAlarmWrite(g_timer2, 2000000 / g_step_hz_r, true);
timerAlarm(g_timer2, 2000000 / g_step_hz_r, true, 0);
digitalWrite(PWM_R, HIGH);
for (int i = 0; i < 100; i++) {
asm("nop \n");
Expand All @@ -87,7 +87,7 @@ void IRAM_ATTR isrL(void)
{
portENTER_CRITICAL_ISR(&g_timer_mux); //割り込み禁止
if (g_motor_move) {
timerAlarmWrite(g_timer3, 2000000 / g_step_hz_l, true);
timerAlarm(g_timer3, 2000000 / g_step_hz_l, true, 0);
digitalWrite(PWM_L, HIGH);
for (int i = 0; i < 100; i++) {
asm("nop \n");
Expand Down Expand Up @@ -122,20 +122,20 @@ void setup()
digitalWrite(PWM_R, LOW);
digitalWrite(PWM_L, LOW);

g_timer0 = timerBegin(0, 80, true); //1us
timerAttachInterrupt(g_timer0, &onTimer0, true);
timerAlarmWrite(g_timer0, 1000, true); //1kHz
timerAlarmEnable(g_timer0);
g_timer0 = timerBegin(1000000); //1us
timerAttachInterrupt(g_timer0, &onTimer0);
timerAlarm(g_timer0, 1000, true, 0); //1kHz
timerStart(g_timer0);

g_timer2 = timerBegin(2, 40, true); //0.5us
timerAttachInterrupt(g_timer2, &isrR, true);
timerAlarmWrite(g_timer2, 13333, true); //150Hz
timerAlarmEnable(g_timer2);
g_timer2 = timerBegin(2000000); //0.5us
timerAttachInterrupt(g_timer2, &isrR);
timerAlarm(g_timer2, 13333, true, 0); //150Hz
timerStart(g_timer2);

g_timer3 = timerBegin(3, 40, true); //0.5us
timerAttachInterrupt(g_timer3, &isrL, true);
timerAlarmWrite(g_timer3, 13333, true); //150Hz
timerAlarmEnable(g_timer3);
g_timer3 = timerBegin(2000000); //0.5us
timerAttachInterrupt(g_timer3, &isrL);
timerAlarm(g_timer3, 13333, true, 0); //150Hz
timerStart(g_timer3);
}

void loop()
Expand Down
Binary file added pico_v2_STEP7_P_control/.DS_Store
Binary file not shown.
42 changes: 21 additions & 21 deletions pico_v2_STEP7_P_control/pico_v2_STEP7_P_control.ino
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void IRAM_ATTR isrR(void)
{
portENTER_CRITICAL_ISR(&g_timer_mux); //割り込み禁止
if (g_motor_move) {
timerAlarmWrite(g_timer2, 2000000 / g_step_hz_r, true);
timerAlarm(g_timer2, 2000000 / g_step_hz_r, true, 0);
digitalWrite(PWM_R, HIGH);
for (int i = 0; i < 100; i++) {
asm("nop \n");
Expand All @@ -140,7 +140,7 @@ void IRAM_ATTR isrL(void)
{
portENTER_CRITICAL_ISR(&g_timer_mux); //割り込み禁止
if (g_motor_move) {
timerAlarmWrite(g_timer3, 2000000 / g_step_hz_l, true);
timerAlarm(g_timer3, 2000000 / g_step_hz_l, true, 0);
digitalWrite(PWM_L, HIGH);
for (int i = 0; i < 100; i++) {
asm("nop \n");
Expand Down Expand Up @@ -182,25 +182,25 @@ void setup()

Serial.begin(115200);

g_timer0 = timerBegin(0, 80, true); //1us
timerAttachInterrupt(g_timer0, &onTimer0, true);
timerAlarmWrite(g_timer0, 1000, true); //1kHz
timerAlarmEnable(g_timer0);

g_timer1 = timerBegin(1, 80, true);
timerAttachInterrupt(g_timer1, &onTimer1, false);
timerAlarmWrite(g_timer1, 500, true);
timerAlarmEnable(g_timer1);

g_timer2 = timerBegin(2, 40, true); //0.5us
timerAttachInterrupt(g_timer2, &isrR, true);
timerAlarmWrite(g_timer2, 13333, true); //150Hz
timerAlarmEnable(g_timer2);

g_timer3 = timerBegin(3, 40, true); //0.5us
timerAttachInterrupt(g_timer3, &isrL, true);
timerAlarmWrite(g_timer3, 13333, true); //150Hz
timerAlarmEnable(g_timer3);
g_timer0 = timerBegin(1000000); //1us
timerAttachInterrupt(g_timer0, &onTimer0);
timerAlarm(g_timer0, 1000, true, 0); //1kHz
timerStart(g_timer0);

g_timer1 = timerBegin(1000000);
timerAttachInterrupt(g_timer1, &onTimer1);
timerAlarm(g_timer1, 500, true, 0);
timerStart(g_timer1);

g_timer2 = timerBegin(2000000); //0.5us
timerAttachInterrupt(g_timer2, &isrR);
timerAlarm(g_timer2, 13333, true, 0); //150Hz
timerStart(g_timer2);

g_timer3 = timerBegin(2000000); //0.5us
timerAttachInterrupt(g_timer3, &isrL);
timerAlarm(g_timer3, 13333, true, 0); //150Hz
timerStart(g_timer3);

g_sen_r.ref = REF_SEN_R;
g_sen_l.ref = REF_SEN_L;
Expand Down
Binary file added pico_v2_STEP8_micromouse/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion pico_v2_STEP8_micromouse/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
//#define SW_CM 2
#define SW_RM 4

#define BUZZER_CH 0


#endif // DEVICE_H_
61 changes: 30 additions & 31 deletions pico_v2_STEP8_micromouse/device.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void IRAM_ATTR isrR(void)
portENTER_CRITICAL_ISR(&g_timer_mux);
if (g_motor_move) {
if (g_step_hz_r < 30) g_step_hz_r = 30;
timerAlarmWrite(g_timer2, 2000000 / g_step_hz_r, true);
timerAlarm(g_timer2, 2000000 / g_step_hz_r, true, 0);
digitalWrite(PWM_R, HIGH);
for (int i = 0; i < 100; i++) {
asm("nop \n");
Expand All @@ -69,7 +69,7 @@ void IRAM_ATTR isrL(void)
portENTER_CRITICAL_ISR(&g_timer_mux);
if (g_motor_move) {
if (g_step_hz_l < 30) g_step_hz_l = 30;
timerAlarmWrite(g_timer3, 2000000 / g_step_hz_l, true);
timerAlarm(g_timer3, 2000000 / g_step_hz_l, true, 0);
digitalWrite(PWM_L, HIGH);
for (int i = 0; i < 100; i++) {
asm("nop \n");
Expand All @@ -80,21 +80,21 @@ void IRAM_ATTR isrL(void)
portEXIT_CRITICAL_ISR(&g_timer_mux);
}

void controlInterruptStart(void) { timerAlarmEnable(g_timer0); }
void controlInterruptStop(void) { timerAlarmDisable(g_timer0); }
void controlInterruptStart(void) { timerStart(g_timer0); }
void controlInterruptStop(void) { timerStop(g_timer0); }

void sensorInterruptStart(void) { timerAlarmEnable(g_timer1); }
void sensorInterruptStop(void) { timerAlarmDisable(g_timer1); }
void sensorInterruptStart(void) { timerStart(g_timer1); }
void sensorInterruptStop(void) { timerStop(g_timer1); }

void PWMInterruptStart(void)
{
timerAlarmEnable(g_timer2);
timerAlarmEnable(g_timer3);
timerStart(g_timer2);
timerStart(g_timer3);
}
void PWMInterruptStop(void)
{
timerAlarmDisable(g_timer2);
timerAlarmDisable(g_timer3);
timerStop(g_timer2);
timerStop(g_timer3);
}

void initAll(void)
Expand All @@ -110,9 +110,8 @@ void initAll(void)
pinMode(SW_L, INPUT);
pinMode(SW_R, INPUT);

ledcSetup(0, 440, 10);
ledcAttachPin(BUZZER, 0);
ledcWrite(0, 1024);
ledcAttach(BUZZER, 440, 10);
ledcWrite(BUZZER, 0);

pinMode(SLED_F, OUTPUT);
pinMode(SLED_S, OUTPUT);
Expand All @@ -137,25 +136,25 @@ void initAll(void)
}
}

g_timer0 = timerBegin(0, 80, true);
timerAttachInterrupt(g_timer0, &onTimer0, false);
timerAlarmWrite(g_timer0, 1000, true);
timerAlarmEnable(g_timer0);
g_timer0 = timerBegin(1000000);
timerAttachInterrupt(g_timer0, &onTimer0);
timerAlarm(g_timer0, 1000, true, 0);
timerStart(g_timer0);

g_timer1 = timerBegin(1, 80, true);
timerAttachInterrupt(g_timer1, &onTimer1, false);
timerAlarmWrite(g_timer1, 500, true);
timerAlarmEnable(g_timer1);
g_timer1 = timerBegin(1000000);
timerAttachInterrupt(g_timer1, &onTimer1);
timerAlarm(g_timer1, 500, true, 0);
timerStart(g_timer1);

g_timer2 = timerBegin(2, 40, true);
timerAttachInterrupt(g_timer2, &isrR, false);
timerAlarmWrite(g_timer2, 13333, true);
timerAlarmEnable(g_timer2);
g_timer2 = timerBegin(2000000);
timerAttachInterrupt(g_timer2, &isrR);
timerAlarm(g_timer2, 13333, true, 0);
timerStart(g_timer2);

g_timer3 = timerBegin(3, 40, true);
timerAttachInterrupt(g_timer3, &isrL, false);
timerAlarmWrite(g_timer3, 13333, true);
timerAlarmEnable(g_timer3);
g_timer3 = timerBegin(2000000);
timerAttachInterrupt(g_timer3, &isrL);
timerAlarm(g_timer3, 13333, true, 0);
timerStart(g_timer3);

Serial.begin(115200);

Expand Down Expand Up @@ -207,10 +206,10 @@ void setBLED(char data)
}

//Buzzer
void enableBuzzer(short f) { ledcWriteTone(BUZZER_CH, f); }
void enableBuzzer(short f) { ledcWriteTone(BUZZER, f); }
void disableBuzzer(void)
{
ledcWrite(BUZZER_CH, 1024); //duty 100% Buzzer OFF
ledcWrite(BUZZER, 0); //duty 0% Buzzer OFF
}

//motor
Expand Down
Loading