Wiki

Reso-nance numérique | Arts et cultures libres

Outils du site


projets:chimeres-orchestra:code-arduino:accueil

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
projets:chimeres-orchestra:code-arduino:accueil [2017/02/10 17:45]
resonance
projets:chimeres-orchestra:code-arduino:accueil [2017/02/10 17:46] (Version actuelle)
resonance [Arduino Chimères OSC]
Ligne 19: Ligne 19:
 Réception des données via le protocole OSC. Réception des données via le protocole OSC.
  
 +++++ chimeres-osc |
 +<code cpp>
 +/*
 + * Chimères Orchestra
 + * =================
 + * Robots drummers in public space by Reson-nance Numérique
 + 
 + * Website:
 + * http://reso-nance.org/chimeres-orchestra 
 + *
 + * Setup: 
 + * Ethernet (OSC) > Ethernet Shield > Arduino MEGA > Power Shield MOSFETS > DC Motors
 + 
 + * Wiring:
 + * Ethernet Shield  Arduino MEGA  Power Shield
 + * ===============  ============  ============
 + * 10               10 (53)     
 + * 11               11 (51)
 + * 12               12 (50)
 + * 13               13 (52)
 + * 5V               5V
 + * GND              GND           GND
 +                  2             3
 +                  3             5
 +                  5             6
 +                  6             9
 +                  7             10
 +                  8             11
 + 
 + * OSC message: 
 + * /arm Id (int 0-5), PWM (int 0-255), Delay (int 0-100)
 + 
 +*/
 +
 +#include <SPI.h>
 +#include <Ethernet.h>
 +#include <ArdOSC.h>
 +
 +#include "PwmMotor.h"
 +
 +// ---- NETWORK ---- //
 +byte myIp[] = { 192, 168, 0, 105 }; // IP
 +int serverPort = 9105; // Receive port
 +byte myMac[] = {  0xED, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address
 +// 101 UDOO
 +// 102 { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }
 +// 103 { 0xEE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }
 +// 104 { 0xDD, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }
 +// 105 { 0xED, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }
 +// 106 { 0xCD, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }
 +
 +char oscmsg[]="/arm";
 +
 +OSCServer server; // to receive messages
 +
 +// ---- CONFIGURATIONS ---- //
 +const int PINS[] = {2,3,5,6,7,8}; // pins Mosfets Shield (for MEGA because Ethernet Shield use 10,11,12,13 pin and 4th pin for SD Card)
 +const int TIME_MAX = 120;
 +const int NB = 6;
 +const int TEMPO = 10; // sampling tempo
 +const boolean DEBUG = true;
 +
 +// ---- MOTORS --------- //
 +int motor_id, motor_pwm, motor_time;
 +PwmMotor motors[NB];
 +unsigned long current = 0;
 +
 +// ---- SETUP ----------- //
 +void setup() {
 + Ethernet.begin(myMac,myIp); 
 + server.begin(serverPort);
 + server.addCallback(oscmsg, &get_osc); // callback function (receive)
 +
 + if (DEBUG) Serial.begin(38400);
 +
 + for (int i=0; i < NB; i++) {
 +     motors[i].init(PINS[i], TIME_MAX, DEBUG);
 +  }
 +}
 +
 +// ---- PROGRAM ----------- //
 +void loop() {
 +  // UPDATE TIME
 +  current = millis();
 +
 +  if(server.availableCheck()>0){
 +    // alive 
 +    }
 +
 +  // MOTOR OFF
 +  for (int i=0; i < NB; i++) {
 +     if( motors[i].isOn() ) motors[i].off(current);
 +  }
 +
 +  delay(TEMPO);
 +}
 +
 +// Get OSC Message
 +void get_osc(OSCMessage *_mes){
 +  motor_id=_mes->getArgInt32(0);
 +  motor_pwm=_mes->getArgInt32(1);
 +  motor_time=_mes->getArgInt32(2);
 +
 +  if (DEBUG) {
 +    Serial.print(motor_id);
 +    Serial.print(motor_pwm);
 +    Serial.println(motor_time);
 +  }
 +  
 +  // MOTOR ON
 +  if( motors[motor_id].isOn() == false ) motors[motor_id].on(current, motor_pwm, motor_time);
 +}
 +</code>
 +++++
 ===== Idem avec capteur de présence (série) ===== ===== Idem avec capteur de présence (série) =====
   * Fichiers : {{:projets:chimeres-orchestra:code-arduino:chimeresorchestra_arduino_sensor_20161104.zip|}}   * Fichiers : {{:projets:chimeres-orchestra:code-arduino:chimeresorchestra_arduino_sensor_20161104.zip|}}
/home/resonancg/www/wiki/data/attic/projets/chimeres-orchestra/code-arduino/accueil.1486745116.txt.gz · Dernière modification: 2017/02/10 17:45 de resonance