Advertisement
Guest User

Untitled

a guest
Jun 5th, 2023
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. #include <Audio.h>
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <SD.h>
  5. #include <SerialFlash.h>
  6. #include <Bounce.h>
  7. #include <ResponsiveAnalogRead.h>
  8. #include <CD74HC4067.h>
  9. CD74HC4067 my_mux(0, 1, 2, 3); // create a new CD74HC4067 object with its four control pins
  10. const int g_common_pin = A1; // select a pin to share with the 16 channels of the CD74HC4067
  11.  
  12. ResponsiveAnalogRead analog(g_common_pin, true);
  13.  
  14.  
  15.  
  16. // GUItool: begin automatically generated code
  17. AudioSynthWaveform waveform1; //xy=110,164
  18. AudioSynthWaveformModulated waveformMod1; //xy=307,171
  19. AudioEffectWaveshaper waveshape1; //xy=485,209
  20. AudioEffectFade fade1; //xy=594,281
  21. AudioMixer4 mixer3; //xy=743,257
  22. AudioEffectDelay delay1; //xy=753,408
  23. AudioMixer4 mixer2; //xy=921,200
  24. AudioOutputI2S i2s1; //xy=1116,197
  25. AudioConnection patchCord1(waveform1, 0, waveformMod1, 0);
  26. AudioConnection patchCord2(waveformMod1, 0, mixer2, 0);
  27. AudioConnection patchCord3(waveformMod1, 0, mixer3, 0);
  28. //AudioConnection patchCord4(waveshape1, fade1);
  29. //AudioConnection patchCord5(fade1, 0, mixer3, 0);
  30. AudioConnection patchCord6(mixer3, delay1);
  31. AudioConnection patchCord7(delay1, 0, mixer2, 1);
  32. AudioConnection patchCord8(delay1, 0, mixer3, 1);
  33. AudioConnection patchCord9(mixer2, 0, i2s1, 0);
  34. AudioConnection patchCord10(mixer2, 0, i2s1, 1);
  35. AudioControlSGTL5000 sgtl5000_1; //xy=289,433
  36. // GUItool: end automatically generated code
  37.  
  38.  
  39.  
  40. int aread[10];
  41. int areadNew[10];
  42. int cycles[10];
  43. int mincycles = 2;
  44. int average[10][4];
  45. int window = 2;
  46.  
  47.  
  48. void setup()
  49. {
  50. Serial.begin(9600);
  51.  
  52. pinMode(g_common_pin, INPUT);
  53. pinMode(4, INPUT_PULLUP);
  54. pinMode(5, INPUT_PULLUP);
  55. pinMode(6, INPUT_PULLUP);
  56. pinMode(9, INPUT_PULLUP);
  57.  
  58. delay(300);
  59. Serial.println("horst hrubsesch");
  60.  
  61. // Audio connections require memory to work. For more
  62. // detailed information, see the MemoryAndCpuUsage example
  63. AudioMemory(200);
  64.  
  65. // Comment these out if not using the audio adaptor board.
  66. sgtl5000_1.enable();
  67. sgtl5000_1.volume(0.5); // caution: very loud - use oscilloscope only!
  68. sgtl5000_1.lineOutLevel(23);
  69.  
  70.  
  71. waveformMod1.amplitude(1.0);
  72. waveformMod1.frequency(400);
  73. waveformMod1.frequencyModulation(4);
  74. waveform1.amplitude(0.0);
  75. waveform1.frequency(1);
  76.  
  77. waveformMod1.begin(1);
  78. waveform1.begin(WAVEFORM_SINE);
  79.  
  80. mixer2.gain(0, 1);
  81.  
  82.  
  83. delay1.delay(0, 330);
  84. mixer3.gain(0, 1);
  85. mixer3.gain(1, 0.5); //feedback
  86. mixer2.gain(1, 1); // wet mix
  87.  
  88.  
  89. Serial.println("setup");
  90. }
  91.  
  92. void readpots()
  93. {
  94.  
  95.  
  96. for (int i = 0; i < 10; i++) {
  97. my_mux.channel(i);
  98. analogRead(g_common_pin);
  99. delayMicroseconds(1500);
  100. areadNew[i] = analogRead(g_common_pin);
  101.  
  102.  
  103. if (areadNew[i] != aread[i]) {
  104. //average[i][cycles[i]] = areadNew[i];
  105. cycles[i]++;
  106.  
  107. }
  108. else cycles[i] = 0;
  109.  
  110. if (cycles[i] >= mincycles) {
  111. cycles[i] = 0;
  112.  
  113. //areadNew[i] = (average[i][0] + average[i][1] + average[i][2] + average[i][3]) >> 2;
  114.  
  115.  
  116.  
  117. if ((areadNew[i] < aread[i] - window) || (areadNew[i] > aread[i] + window)) {
  118. aread[i] = (aread[i] + areadNew[i]) >> 1;
  119. if (aread[i] < 3) {
  120. aread[i] = 0;
  121. }
  122. if (aread[i] > 1020) {
  123. aread[i] = 1023;
  124. }
  125. }
  126.  
  127. }
  128. Serial.print(aread[i]);
  129. Serial.print(" - ");
  130. }
  131. Serial.println();
  132.  
  133. }
  134.  
  135. void loop()
  136. {
  137. readpots();
  138.  
  139. if (!digitalRead(4)) {
  140. Serial.println("fire");
  141. mixer2.gain(0, 1);
  142. mixer3.gain(0, 1);
  143. }
  144. else {
  145. Serial.println("no");
  146. mixer2.gain(0, 0);
  147. mixer3.gain(0, 0);
  148. }
  149.  
  150.  
  151.  
  152.  
  153. waveform1.amplitude((float)aread[8] / 1023);
  154. waveform1.frequency((float)aread[9] / 50);
  155. mixer2.gain(1, (float)aread[4] / 1023); //delay wet
  156. mixer3.gain(1, (float)aread[5] / 512); //delay feedback
  157. delay1.delay(0, (aread[6] >> 2) + 50); //delay time
  158. waveformMod1.amplitude((float) aread[2] / 1023); //main vol
  159. waveformMod1.frequency((aread[0] << 2) + 40); // vco freq
  160.  
  161. //Serial.println("x");
  162.  
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement