Advertisement
Guest User

Iot-kadai1

a guest
Sep 9th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pitches.h"
  2. #include "ramen.h"
  3. #include "onkai.h"
  4.  
  5. #define LEDC_CHANNEL_0 0
  6. #define LEDC_TIMER_13_BIT  13
  7. #define LEDC_BASE_FREQ  5000
  8.  
  9. #define bzz 16
  10.  
  11. #define start_sw 4
  12. #define inter_sw 32
  13.  
  14. #define LED_G 5
  15. #define LED_R 14
  16.  
  17. #define tempo_l 1000
  18. #define delayTime 100
  19. #define onkai_s 20
  20. #define onkai_max 8
  21. /*
  22. int arrayN2 = sizeof onkai;
  23. int c2 = sizeof onkai[0];
  24. int arrayS2 = arrayN2 / c2;
  25. */
  26.  
  27. int arrayN = sizeof melody;
  28. int c = sizeof melody[0];
  29. int arrayS = arrayN / c;
  30.  
  31. int start_flag = 0; //スタート検知
  32.  
  33. void setup() {
  34.  
  35.   ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT);
  36.   ledcAttachPin(bzz, LEDC_CHANNEL_0);
  37.  
  38.   pinMode(bzz, OUTPUT);
  39.   pinMode(LED_G, OUTPUT);
  40.   pinMode(LED_R, OUTPUT);
  41.   pinMode(start_sw, INPUT_PULLUP);
  42.   pinMode(inter_sw, INPUT_PULLUP);
  43. }
  44. void tone_n(int channel, int frq, int time_w) {
  45.   ledcWriteTone (channel, frq);
  46.   delay(time_w);
  47.   ledcWriteTone (channel, 0);
  48. }
  49.  
  50. void loop() {
  51.   start_flag =!(digitalRead(start_sw));
  52.   digitalWrite(LED_G, HIGH);
  53.  
  54.   if (start_flag) {
  55.     digitalWrite(LED_G, LOW);
  56.     delay(tempo_l-onkai_s);
  57.  
  58.     for (int cnt = 0; cnt < onkai_max; cnt++) {
  59.     digitalWrite(LED_R, HIGH);
  60.     tone_n(LEDC_CHANNEL_0, onkai[cnt], onkai_s);
  61.     digitalWrite(LED_R, LOW);
  62.     delay(tempo_l-onkai_s);
  63.   }
  64.     digitalWrite(LED_R, LOW);
  65.     digitalWrite(LED_G, HIGH);
  66.  
  67.     for (int cnt = 0; cnt < arrayS; cnt++) {
  68.     tone_n(LEDC_CHANNEL_0, melody[cnt], tempo[cnt]);
  69.     delay(delayTime);
  70.   }
  71.   ledcWriteTone (LEDC_CHANNEL_0, 0);
  72.   }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement