Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
projets:light-synth:accueil [2017/07/20 12:29] resonance [Notes techniques] |
projets:light-synth:accueil [2018/06/09 11:33] (Version actuelle) resonance [Boite a rythme a led] |
||
|---|---|---|---|
| Ligne 4: | Ligne 4: | ||
| * Licence : [[http:// | * Licence : [[http:// | ||
| * Description : synthé qui marche avec la lumiere | * Description : synthé qui marche avec la lumiere | ||
| - | * Fichiers sources : //mettre un lien// | + | * Fichiers sources : voir plus bas pour les codes , design : {{ : |
| * Lien : //mettre un lien// | * Lien : //mettre un lien// | ||
| Ligne 11: | Ligne 11: | ||
| ===== Note d' | ===== Note d' | ||
| Synthé qui marche avec la lumiere : | Synthé qui marche avec la lumiere : | ||
| - | Plusieurs pistes sont possible, notamment en changeant les frequences | + | Plusieurs pistes sont possible, notamment en changeant les fréquences |
| {{projets: | {{projets: | ||
| Ligne 22: | Ligne 22: | ||
| {{youtube> | {{youtube> | ||
| + | //Le troisieme synth de la video est l' | ||
| - | ==== Code pour communiquer avec PureData COMPORT (2 led branché en 9 et 10): ==== | ||
| - | On controle ainsi deux pins avec tone depuis Pure Data... | ||
| - | |||
| - | **Patch PureData :** voir fichier 4 dans la page ressource [[http:// | ||
| - | |||
| - | ++++ Le code | ||
| - | <code c+> | ||
| - | String inputString = ""; | ||
| - | boolean stringComplete = false; | ||
| - | String fct =""; | ||
| - | String arg=""; | ||
| - | int index; | ||
| - | |||
| - | #include < | ||
| - | Tone freq1; | ||
| - | Tone freq2; | ||
| - | |||
| - | void setup() { | ||
| - | Serial.begin(9600); | ||
| - | freq1.begin(9); | ||
| - | freq2.begin(10); | ||
| - | } | ||
| - | |||
| - | void loop() { | ||
| - | if (stringComplete) { | ||
| - | // | ||
| - | index = inputString.indexOf(' | ||
| - | fct = inputString.substring(0, | ||
| - | arg = inputString.substring(index, | ||
| - | | ||
| - | if (fct == " | ||
| - | freq2.play(arg.toInt(), | ||
| - | } | ||
| - | else if (fct == " | ||
| - | freq1.play(arg.toInt(), | ||
| - | } | ||
| - | |||
| - | inputString = ""; | ||
| - | stringComplete = false; | ||
| - | } | ||
| - | } | ||
| - | |||
| - | /* | ||
| - | SerialEvent est déclenché quand de nouvelles données sont reçues. | ||
| - | Cett routine tourne entre chaque loop(), donc utiliser un delay la fait aussi attendre | ||
| - | */ | ||
| - | void serialEvent() { | ||
| - | while (Serial.available()) { | ||
| - | char inChar = (char)Serial.read(); | ||
| - | inputString += inChar; // concaténation des octets | ||
| - | if (inChar == ' | ||
| - | stringComplete = true; | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | |||
| - | |||
| - | </ | ||
| - | ++++ | ||
| ==== Boite a rythme a led ==== | ==== Boite a rythme a led ==== | ||
| Ligne 92: | Ligne 34: | ||
| <code c+> | <code c+> | ||
| - | // 3 led au pin 11/ | + | // 3 led a jouant a la noire, croche et triolet |
| // un potentiometre 10k en A0 : controle le tempo général... | // un potentiometre 10k en A0 : controle le tempo général... | ||
| // une photo resistance en A1 : controle un effet de delay | // une photo resistance en A1 : controle un effet de delay | ||
| - | #define led1 11 // | + | #define led1 5 |
| - | #define led2 12 //pin for each led | + | #define led2 9 |
| - | #define led3 13 //pin for each led | + | #define led3 10 |
| - | #define factor 6 //pin for each led | + | #define factor 6 //factor |
| unsigned long previousMillis[3]; | unsigned long previousMillis[3]; | ||
| Ligne 199: | Ligne 141: | ||
| ++++ | ++++ | ||
| - | ==== Synth fm avec 5 potentiomètres ==== | + | ==== Synth fm avec 5 potentiomètres |
| On controle un synthe fm avec 5 potards, | On controle un synthe fm avec 5 potards, | ||
| le son passe par la led en pin 9... | le son passe par la led en pin 9... | ||
| Ligne 345: | Ligne 287: | ||
| ++++ | ++++ | ||
| + | ==== Code pour communiquer avec PureData COMPORT (2 led branché en 9 et 10): ==== | ||
| + | On controle ainsi deux pins avec tone depuis Pure Data... | ||
| + | **Patch PureData :** voir fichier 4 dans la page ressource [[http:// | ||
| + | ++++ Le code | ||
| + | <code c+> | ||
| + | String inputString = ""; | ||
| + | boolean stringComplete = false; | ||
| + | String fct =""; | ||
| + | String arg=""; | ||
| + | int index; | ||
| + | |||
| + | #include < | ||
| + | Tone freq1; | ||
| + | Tone freq2; | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(9600); | ||
| + | freq1.begin(9); | ||
| + | freq2.begin(10); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | if (stringComplete) { | ||
| + | // | ||
| + | index = inputString.indexOf(' | ||
| + | fct = inputString.substring(0, | ||
| + | arg = inputString.substring(index, | ||
| + | | ||
| + | if (fct == " | ||
| + | freq2.play(arg.toInt(), | ||
| + | } | ||
| + | else if (fct == " | ||
| + | freq1.play(arg.toInt(), | ||
| + | } | ||
| + | |||
| + | inputString = ""; | ||
| + | stringComplete = false; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | /* | ||
| + | SerialEvent est déclenché quand de nouvelles données sont reçues. | ||
| + | Cett routine tourne entre chaque loop(), donc utiliser un delay la fait aussi attendre | ||
| + | */ | ||
| + | void serialEvent() { | ||
| + | while (Serial.available()) { | ||
| + | char inChar = (char)Serial.read(); | ||
| + | inputString += inChar; // concaténation des octets | ||
| + | if (inChar == ' | ||
| + | stringComplete = true; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | </ | ||
| + | ++++ | ||
| + | |||
| + | ==== Code sympa fluctuant Mozzi ==== | ||
| + | 2 pot volume et pitch | ||
| + | |||
| + | ++++ Le code | ||
| + | <code c+> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | const char KNOB_PIN = 0; // set the input for the knob to analog pin 0 | ||
| + | const char LDR_PIN = 1; // set the input for the LDR to analog pin 1 | ||
| + | |||
| + | // use: Oscil < | ||
| + | Oscil < | ||
| + | |||
| + | byte volume; | ||
| + | |||
| + | void setup(){ | ||
| + | startMozzi(); | ||
| + | } | ||
| + | |||
| + | |||
| + | void updateControl(){ | ||
| + | // read the potentiometer | ||
| + | int knob_value = mozziAnalogRead(KNOB_PIN); | ||
| + | | ||
| + | // map it to an 8 bit volume range for efficient calculations in updateAudio | ||
| + | volume = knob_value >> 2; // 10 bits (0-> | ||
| + | | ||
| + | // read the light dependent resistor | ||
| + | int light_level = mozziAnalogRead(LDR_PIN); | ||
| + | |||
| + | light_level = map(light_level, | ||
| + | light_level = light_level*100 + 200; | ||
| + | |||
| + | // set the frequency | ||
| + | aSin.setFreq( light_level); | ||
| + | | ||
| + | } | ||
| + | |||
| + | |||
| + | int updateAudio(){ | ||
| + | // cast char output from aSin.next() to int to make room for multiplication | ||
| + | return ((int)aSin.next() * volume) >> 8; // shift back into range after multiplying by 8 bit value | ||
| + | |||
| + | } | ||
| + | |||
| + | void loop(){ | ||
| + | audioHook(); | ||
| + | delay(100); | ||
| + | } | ||
| + | </ | ||
| + | ++++ | ||
| + | |||
| + | ==== Theremin fluctuant Mozzi ==== | ||
| + | 2 pot (selecteur si pot ou ldr pour controler le pitch, pitch ) un ldr (pitch).... | ||
| + | |||
| + | ++++ Le code | ||
| + | <code c+> | ||
| + | / | ||
| + | */ | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | #define INPUT_PIN 0 // analog control input | ||
| + | #define INPUT_PINA 2 // analog control input | ||
| + | #define MIX_PIN 3 // analog control input | ||
| + | |||
| + | unsigned int echo_cells_1 = 32; | ||
| + | unsigned int echo_cells_2 = 60; | ||
| + | unsigned int echo_cells_3 = 127; | ||
| + | int bumpy_input = 12; | ||
| + | |||
| + | #define CONTROL_RATE 64 | ||
| + | ControlDelay <128, int> kDelay; // 2seconds | ||
| + | |||
| + | // oscils to compare bumpy to averaged control input | ||
| + | Oscil < | ||
| + | Oscil < | ||
| + | Oscil < | ||
| + | Oscil < | ||
| + | |||
| + | // use: RollingAverage < | ||
| + | RollingAverage <int, 32> kAverage; // how_many_to_average has to be power of 2 | ||
| + | int averaged; | ||
| + | |||
| + | void setup(){ | ||
| + | kDelay.set(echo_cells_1); | ||
| + | startMozzi(); | ||
| + | } | ||
| + | |||
| + | |||
| + | void updateControl(){ | ||
| + | int mix = mozziAnalogRead(MIX_PIN); | ||
| + | int pot = mozziAnalogRead(INPUT_PINA) ; | ||
| + | int ldr = mozziAnalogRead(INPUT_PIN) ; | ||
| + | |||
| + | if (mix > 500) | ||
| + | { | ||
| + | bumpy_input = ldr; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | bumpy_input = pot; | ||
| + | } | ||
| + | |||
| + | | ||
| + | averaged = kAverage.next(bumpy_input); | ||
| + | aSin0.setFreq(averaged); | ||
| + | aSin1.setFreq(kDelay.next(averaged)); | ||
| + | aSin2.setFreq(kDelay.read(echo_cells_2)); | ||
| + | aSin3.setFreq(kDelay.read(echo_cells_3)); | ||
| + | } | ||
| + | |||
| + | |||
| + | int updateAudio(){ | ||
| + | return 3*((int)aSin0.next()+aSin1.next()+(aSin2.next()>> | ||
| + | +(aSin3.next()>> | ||
| + | } | ||
| + | |||
| + | |||
| + | void loop(){ | ||
| + | audioHook(); | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | ++++ | ||
| ===== Matériaux et outils ===== | ===== Matériaux et outils ===== | ||