/* * Platine sequenceur / prototype 002 * http://lesporteslogiques.net/wiki/openatelier/projet/platine_sequenceur * Quimper, La baleine, 24 sept 2020 * Debian 9.5 @ kirin / arduino 1.8.5 * + library Adafruit NeoPixel 1.1.3 https://github.com/adafruit/Adafruit_NeoPixel * * CIRCUIT * - 6 phototransistors reliés aux entrées analogiques * - ruban de 8 leds RGB * * MODES DE FONCTIONNEMENT (à régler dans le code) * Mode de réception des données (les données envoyées ne sont pas formatées de la même manière) * 0 pour le mode de test (traceur serie de l'arduino IDE) * 1 pour le mode de réception dans pure data * * VERSIONS * 001 : (prototype 001, photorésistances) envoi de valeurs brutes en série * 002 : (prototype 001, photorésistances) ajout des leds + calibration * 003 : (prototype 002, phototransistors) * * TODO * ajouter un bouton de calibration * ajouter un switch de mode 0 ou 1 * ajouter une led (clignote = calibration, éteinte mode 0, allumée mode 1) * * RESSOURCES * - traitements de lissage des données : https://www.openprocessing.org/sketch/686436 */ int MODE = 0; // Inclure les bibliothèques de fonction (libraries) nécessaires #include #ifdef __AVR__ #include #endif #define BROCHE_PT1 A1 // Broche reliée au phototransistor 1 #define BROCHE_PT2 A2 // Broche reliée au phototransistor 2 #define BROCHE_PT3 A3 // Broche reliée au phototransistor 3 #define BROCHE_PT4 A4 // Broche reliée au phototransistor 4 #define BROCHE_PT5 A5 // Broche reliée au phototransistor 5 #define BROCHE_PT6 A6 // Broche reliée au phototransistor 6 #define BROCHE_LED 5 // A quelle broche est relié le ruban de LEDs ? #define NUMPIXELS 6 // Combien de LEDs sur le ruban ? // Créer l'objet correspondant au ruban de LEDs Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, BROCHE_LED, NEO_RGB + NEO_KHZ800); int luminosite = 255; int v1b, v2b, v3b, v4b, v5b, v6b; // valeurs brutes int v1l, v2l, v3l, v4l, v5l, v6l; // valeurs lissées int v1c, v2c, v3c, v4c, v5c, v6c; // valeurs calibrées boolean CALIBRATION = true; long v1s, v2s, v3s, v4s, v5s, v6s; // sommes utilisées pour la calibration int v1i, v2i, v3i, v4i, v5i, v6i; // valeurs d'initialisation définies pendant la phase de calibration int calibration_start; // démarrage de la calibration à cette milliseconde! int calibration_compteur = 0; // utlisé pour le calcul réactualisé des moyennes void setup() { pixels.begin(); // Initialiser l'objet du ruban de leds Serial.begin(57600); // Fixer la luminosité pour l'ensemble du ruban pixels.setBrightness(luminosite); // Définir une couleur identique pour chaque LED, la LED 0 est la plus proche des broches for (int i = 0; i < 6; i++) { pixels.setPixelColor(i, pixels.Color( 255, 255, 255 )); } pixels.show(); delay(500); calibration_start = millis(); } void loop () { if (CALIBRATION) { calibration_compteur ++; if (millis() - calibration_start > 3000) { // L'étape de calibration dure 3 secondes CALIBRATION = false; v1i = (int)(v1s / (calibration_compteur - 1) ); v2i = (int)(v2s / (calibration_compteur - 1) ); v3i = (int)(v3s / (calibration_compteur - 1) ); v4i = (int)(v4s / (calibration_compteur - 1) ); v5i = (int)(v5s / (calibration_compteur - 1) ); v6i = (int)(v6s / (calibration_compteur - 1) ); v1l = v1i; v2l = v2i; v3l = v3i; v4l = v4i; v5l = v5i; v6l = v6i; } else { v1s += analogRead(BROCHE_PT1); delayMicroseconds(3); v2s += analogRead(BROCHE_PT2); delayMicroseconds(3); v3s += analogRead(BROCHE_PT3); delayMicroseconds(3); v4s += analogRead(BROCHE_PT4); delayMicroseconds(3); v5s += analogRead(BROCHE_PT5); delayMicroseconds(3); v6s += analogRead(BROCHE_PT6); delayMicroseconds(3); } } if (!CALIBRATION) { // Récupérer les valeurs actuelles v1b = analogRead(BROCHE_PT1); delayMicroseconds(3); v2b = analogRead(BROCHE_PT2); delayMicroseconds(3); v3b = analogRead(BROCHE_PT3); delayMicroseconds(3); v4b = analogRead(BROCHE_PT4); delayMicroseconds(3); v5b = analogRead(BROCHE_PT5); delayMicroseconds(3); v6b = analogRead(BROCHE_PT6); delayMicroseconds(3); v1l = (0.85 * v1l) + (0.15 * v1b) ; v2l = (0.85 * v2l) + (0.15 * v2b) ; v3l = (0.85 * v3l) + (0.15 * v3b) ; v4l = (0.85 * v4l) + (0.15 * v4b) ; v5l = (0.85 * v5l) + (0.15 * v5b) ; v6l = (0.85 * v6l) + (0.15 * v6b) ; v1c = (v1l - v1i) * -1; v2c = (v2l - v2i) * -1; v3c = (v3l - v3i) * -1; v4c = (v4l - v4i) * -1; v5c = (v5l - v5i) * -1; v6c = (v6l - v6i) * -1; if (MODE == 0) { Serial.print(v1c); Serial.print(","); Serial.print(v2c); Serial.print(","); Serial.print(v3c); Serial.print(","); Serial.print(v4c); Serial.print(","); Serial.print(v5c); Serial.print(","); Serial.println(v6c); //Serial.println(""); } if (MODE == 1) { Serial.print("photores "); Serial.print(v1c); Serial.print(" "); Serial.print(v2c); Serial.print(" "); Serial.print(v3c); Serial.print(" "); Serial.print(v4c); Serial.print(" "); Serial.print(v5c); Serial.print(" "); Serial.println(v6c); } delay(5); } }