Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pitches.h"
- #include "ramen.h"
- #include "onkai.h"
- #define LEDC_CHANNEL_0 0
- #define LEDC_TIMER_13_BIT 13
- #define LEDC_BASE_FREQ 5000
- #define bzz 16
- #define start_sw 4
- #define inter_sw 32
- #define LED_G 5
- #define LED_R 14
- #define tempo_l 1000
- #define delayTime 100
- #define onkai_s 20
- #define onkai_max 8
- /*
- int arrayN2 = sizeof onkai;
- int c2 = sizeof onkai[0];
- int arrayS2 = arrayN2 / c2;
- */
- int arrayN = sizeof melody;
- int c = sizeof melody[0];
- int arrayS = arrayN / c;
- int start_flag = 0; //スタート検知
- void setup() {
- ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT);
- ledcAttachPin(bzz, LEDC_CHANNEL_0);
- pinMode(bzz, OUTPUT);
- pinMode(LED_G, OUTPUT);
- pinMode(LED_R, OUTPUT);
- pinMode(start_sw, INPUT_PULLUP);
- pinMode(inter_sw, INPUT_PULLUP);
- }
- void tone_n(int channel, int frq, int time_w) {
- ledcWriteTone (channel, frq);
- delay(time_w);
- ledcWriteTone (channel, 0);
- }
- void loop() {
- start_flag =!(digitalRead(start_sw));
- digitalWrite(LED_G, HIGH);
- if (start_flag) {
- digitalWrite(LED_G, LOW);
- delay(tempo_l-onkai_s);
- for (int cnt = 0; cnt < onkai_max; cnt++) {
- digitalWrite(LED_R, HIGH);
- tone_n(LEDC_CHANNEL_0, onkai[cnt], onkai_s);
- digitalWrite(LED_R, LOW);
- delay(tempo_l-onkai_s);
- }
- digitalWrite(LED_R, LOW);
- digitalWrite(LED_G, HIGH);
- for (int cnt = 0; cnt < arrayS; cnt++) {
- tone_n(LEDC_CHANNEL_0, melody[cnt], tempo[cnt]);
- delay(delayTime);
- }
- ledcWriteTone (LEDC_CHANNEL_0, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement