1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
| #include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include <Audio.h>
#include <SerialFlash.h>
#include "Adafruit_TCS34725.h"
extern "C" {
#include "utility/twi.h" // from Wire library, so we can do bus scanning
}
#define TCAADDR 0x70 // Adresse du multiplexeur
void tcaselect(uint8_t i) { // Selection de la sortie du multiplexeur
if (i > 7) return; // La sortie selectionnee doit être < à 7
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i); // Envoie un octet nul avec un bit positif positionné sur sortie désirée:
// Ex: 1er sortie: 00000001 | 3e sortie: 00000100
Wire.endTransmission();
}
// GUItool: begin automatically generated code
AudioOutputI2S i2s1; //xy=1008,322
AudioSynthWaveformSine sine[7];
/*
AudioSynthWaveformSine sine1; //xy=122,142
AudioSynthWaveformSine sine2; //xy=120,199
AudioSynthWaveformSine sine3; //xy=119,249
AudioSynthWaveformSine sine4; //xy=118,305
AudioSynthWaveformSine sine5; //xy=118,365
AudioSynthWaveformSine sine6; //xy=116,422
AudioSynthWaveformSine sine7; //xy=115,472
*/
AudioEffectEnvelope envelope[7];
/*
AudioEffectEnvelope envelope1; //xy=280,143
AudioEffectEnvelope envelope2; //xy=280,200
AudioEffectEnvelope envelope3; //xy=279,249
AudioEffectEnvelope envelope4; //xy=281,305
AudioEffectEnvelope envelope5; //xy=276,366
AudioEffectEnvelope envelope6; //xy=276,423
AudioEffectEnvelope envelope7; //xy=275,472
*/
AudioMixer4 mixer1; //xy=527,225
AudioMixer4 mixer2; //xy=527,394
AudioMixer4 mixer3; //xy=758,318
AudioConnection patchCord7(sine[0], envelope[0]);
AudioConnection patchCord6(sine[1], envelope[1]);
AudioConnection patchCord5(sine[2], envelope[2]);
AudioConnection patchCord3(sine[3], envelope[3]);
AudioConnection patchCord4(sine[4], envelope[4]);
AudioConnection patchCord2(sine[5], envelope[5]);
AudioConnection patchCord1(sine[6], envelope[6]);
AudioConnection patchCord12(envelope[0], 0, mixer1, 0);
AudioConnection patchCord13(envelope[1], 0, mixer1, 1);
AudioConnection patchCord11(envelope[2], 0, mixer1, 2);
AudioConnection patchCord14(envelope[3], 0, mixer1, 3);
AudioConnection patchCord9(envelope[4], 0, mixer2, 0);
AudioConnection patchCord10(envelope[5], 0, mixer2, 1);
AudioConnection patchCord8(envelope[6], 0, mixer2, 2);
AudioConnection patchCord15(mixer1, 0, mixer3, 0);
AudioConnection patchCord16(mixer2, 0, mixer3, 1);
AudioConnection patchCord17(mixer3, 0, i2s1, 0);
AudioConnection patchCord18(mixer3, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=126,37
// GUItool: end automatically generated code
float outputLevel = (float)analogRead(A1) / 1023.0;
float notesPlaying[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
Adafruit_TCS34725 colorSensor[7] = {Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_16X),
Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_16X),
Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_16X),
Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_16X),
Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_16X),
Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_16X),
Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_16X)};
uint16_t rSensor, gSensor, bSensor, cSensor;
float freqSine[7] = {523.25, 587.33, 659.26, 698.46, 783.99, 880.00, 987.77};
void setup(void) {
// while (!Serial);
// delay(1000);
Wire.begin();
Serial.begin(115200);
// Audio setup
AudioMemory(20);
sgtl5000_1.enable();
sgtl5000_1.volume(outputLevel);
mixer1.gain(0, 0.25);
mixer1.gain(1, 0.25);
mixer1.gain(2, 0.25);
mixer1.gain(3, 0.25);
mixer2.gain(0, 0.25);
mixer2.gain(1, 0.25);
mixer2.gain(2, 0.25);
mixer3.gain(0, 0.5);
mixer3.gain(1, 0.5);
sine[0].frequency(523.25);
sine[0].amplitude(1.0);
sine[1].frequency(587.33);
sine[1].amplitude(1.0);
sine[2].frequency(659.26);
sine[2].amplitude(1.0);
sine[3].frequency(698.46);
sine[3].amplitude(1.0);
sine[4].frequency(783.99);
sine[4].amplitude(1.0);
sine[5].frequency(880.00);
sine[5].amplitude(1.0);
sine[6].frequency(987.77);
sine[6].amplitude(1.0);
// Color sensor setup
for (uint8_t sensorIndex=0; sensorIndex < 7; sensorIndex++) {
tcaselect(sensorIndex + 1);
Serial.print("TCA Port #"); Serial.println(sensorIndex + 1);
if (colorSensor[sensorIndex].begin()) {
Serial.println("Found sensor " + String(sensorIndex));
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
}
}
void loop() {
// Ajuste le volume en fonction de la position du potentiometre
outputLevel = analogRead(A1) / 1023.0;
sgtl5000_1.volume(outputLevel);
// Itération sur les sorties du multiplexeur
for (uint8_t sensorIndex=0; sensorIndex < 7; sensorIndex++) {
tcaselect(sensorIndex + 1);
//Serial.print("TCA Port #"); Serial.println(sensorIndex + 1);
// Lit les valeurs du capteur de couleurs
colorSensor[sensorIndex].getRawData(&rSensor, &gSensor, &bSensor, &cSensor);
// Détermine la couleur captée:
// 0: Blanc | 0.5: Bleu | 1: Rose | 2: Vert
notesPlaying[sensorIndex] = (rSensor > 110) ? 1 : ((rSensor > 90) ? 0 : ((rSensor > 50) ? 2 : 0.5));
// Affiche la couleur du premier capteur dans le terminal
// Serial.println(notesPlaying[sensorIndex] == 0.0 ? "Blanc" : (notesPlaying[sensorIndex] == 0.5) ? "Bleu" : (notesPlaying[sensorIndex] == 1.0) ? "Rose" : "Vert");
}
Serial.println(String(notesPlaying[0]) + ", " + String(notesPlaying[1]) + ", " + String(notesPlaying[2]) + ", " + String(notesPlaying[3]) + ", " + String(notesPlaying[4]) + ", " + String(notesPlaying[5]) + ", " + String(notesPlaying[6]));
for (uint8_t genIndex = 0; genIndex < 7; genIndex++) {
// Active / desactive l'enveloppe des voies actives
if ((notesPlaying[genIndex] != 0) && (envelope[genIndex].isActive() == false)) {
sine[genIndex].frequency(freqSine[genIndex] * notesPlaying[genIndex]);
envelope[genIndex].noteOn();
// Serial.println("Do: On");
} else if ((notesPlaying[genIndex] == 0) && (envelope[genIndex].isActive() == true)) {
envelope[genIndex].noteOff();
// Serial.println("Do: Off");
}
}
// if ((notesPlaying[1] != 0) && (envelope2.isActive() == false)) {
// sine2.frequency(587.33 * notesPlaying[1]);
// envelope2.noteOn();
// // Serial.println("Re: On");
// } else if ((notesPlaying[1] == 0) && (envelope2.isActive() == true)) {
// envelope2.noteOff();
// // Serial.println("Re: Off");
// }
//
// if ((notesPlaying[2] != 0) && (envelope3.isActive() == false)) {
// sine3.frequency(659.26 * notesPlaying[2]);
// envelope3.noteOn();
// // Serial.println("Mi: On");
// } else if ((notesPlaying[2] == 0) && (envelope3.isActive() == true)) {
// envelope3.noteOff();
// // Serial.println("Mi: Off");
// }
//
// if ((notesPlaying[3] != 0) && (envelope4.isActive() == false)) {
// sine4.frequency(698.46 * notesPlaying[3]);
// envelope4.noteOn();
// // Serial.println("Fa: On");
// } else if ((notesPlaying[3] == 0) && (envelope4.isActive() == true)) {
// envelope4.noteOff();
// // Serial.println("Fa: Off");
// }
//
// if ((notesPlaying[4] != 0) && (envelope5.isActive() == false)) {
// sine5.frequency(783.99 * notesPlaying[4]);
// envelope5.noteOn();
// // Serial.println("Sol: On");
// } else if ((notesPlaying[4] == 0) && (envelope5.isActive() == true)) {
// envelope5.noteOff();
// // Serial.println("Sol: Off");
// }
//
// if ((notesPlaying[5] != 0) && (envelope6.isActive() == false)) {
// sine6.frequency(880.00 * notesPlaying[5]);
// envelope6.noteOn();
// // Serial.println("La: On");
// } else if ((notesPlaying[5] == 0) && (envelope6.isActive() == true)) {
// envelope6.noteOff();
// // Serial.println("La: Off");
// }
//
// if ((notesPlaying[6] != 0) && (envelope7.isActive() == false)) {
// sine7.frequency(987.77 * notesPlaying[6]);
// envelope7.noteOn();
// // Serial.println("Si: On");
// } else if ((notesPlaying[6] == 0) && (envelope7.isActive() == true)) {
// envelope7.noteOff();
// // Serial.println("Si: Off");
// }
} |
Partager