Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

67 lines
1.5KB

  1. #include <Bounce.h>
  2. #include <Audio.h>
  3. #include <Wire.h>
  4. #include <SPI.h>
  5. #include <SD.h>
  6. #include <SerialFlash.h>
  7. #include "BasicFlute1_samples.h"
  8. AudioSynthWavetable wavetable;
  9. AudioOutputI2S i2s1;
  10. AudioMixer4 mixer;
  11. AudioConnection patchCord1(wavetable, 0, mixer, 0);
  12. AudioConnection patchCord2(mixer, 0, i2s1, 0);
  13. AudioConnection patchCord3(mixer, 0, i2s1, 1);
  14. AudioControlSGTL5000 sgtl5000_1;
  15. // Bounce objects to read pushbuttons
  16. Bounce button0 = Bounce(0, 15);
  17. Bounce button1 = Bounce(1, 15); // 15 ms debounce time
  18. Bounce button2 = Bounce(2, 15);
  19. void setup() {
  20. Serial.begin(115200);
  21. pinMode(0, INPUT_PULLUP);
  22. pinMode(1, INPUT_PULLUP);
  23. pinMode(2, INPUT_PULLUP);
  24. AudioMemory(20);
  25. sgtl5000_1.enable();
  26. sgtl5000_1.volume(0.8);
  27. mixer.gain(0, 0.7);
  28. wavetable.setInstrument(BasicFlute1);
  29. wavetable.amplitude(1);
  30. }
  31. bool playing = false;
  32. void loop() {
  33. // Update all the button objects
  34. button0.update();
  35. button1.update();
  36. button2.update();
  37. //Read knob values
  38. int knob1 = analogRead(A3);
  39. int knob2 = analogRead(A2);
  40. //Get frequency and gain from knobs
  41. float freq = (float)knob1/5.0;
  42. float gain = (float)knob2/1023.0;
  43. //Set a low-limit to the gain
  44. if (gain < .05) gain = .05;
  45. if (button1.fallingEdge()) {
  46. if (playing) {
  47. playing = false;
  48. wavetable.stop();
  49. }
  50. else {
  51. playing = true;
  52. wavetable.playFrequency(freq);
  53. wavetable.amplitude(gain);
  54. }
  55. }
  56. wavetable.amplitude(gain);
  57. wavetable.setFrequency(freq);
  58. }