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:chimeres-orchestra:code-arduino:accueil [2016/11/11 00:08] resonance  | 
                
                    projets:chimeres-orchestra:code-arduino:accueil [2017/02/10 17:46] (Version actuelle) resonance [Arduino Chimères OSC]  | 
            ||
|---|---|---|---|
| Ligne 13: | Ligne 13: | ||
| </ | </ | ||
| + | |||
| + | ===== Arduino Chimères OSC ===== | ||
| + |   * Fichiers : {{: | ||
| + | |||
| + | 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:// | ||
| + | * | ||
| + |  * Setup:  | ||
| + | * Ethernet (OSC) > Ethernet Shield > Arduino MEGA > Power Shield MOSFETS > DC Motors | ||
| + |   | ||
| + | * Wiring: | ||
| + |  * Ethernet Shield  | ||
| + |  * ===============  | ||
| + | * 10 10 (53) | ||
| + | * 11 11 (51) | ||
| + | * 12 12 (50) | ||
| + | * 13 13 (52) | ||
| + | * 5V 5V | ||
| + | * GND GND GND | ||
| + |   | ||
| + |   | ||
| + |   | ||
| + |   | ||
| + |   | ||
| + |   | ||
| + |   | ||
| + |  * OSC message:  | ||
| + | * /arm Id (int 0-5), PWM (int 0-255), Delay (int 0-100) | ||
| + |   | ||
| + | */ | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | #include " | ||
| + | |||
| + | // ---- 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[]="/ | ||
| + | |||
| + | OSCServer server; // to receive messages | ||
| + | |||
| + | // ---- CONFIGURATIONS ---- // | ||
| + | const int PINS[] = {2, | ||
| + | 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() { | ||
| + |   | ||
| + |   | ||
| + |   | ||
| + | |||
| + |  if (DEBUG) Serial.begin(38400); | ||
| + | |||
| + | for (int i=0; i < NB; i++) { | ||
| + |       | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // ---- PROGRAM ----------- // | ||
| + | void loop() { | ||
| + | // UPDATE TIME | ||
| + | current = millis(); | ||
| + | |||
| + |   if(server.availableCheck()> | ||
| + | // 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-> | ||
| + |   motor_pwm=_mes-> | ||
| + |   motor_time=_mes-> | ||
| + | |||
| + | 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, | ||
| + | } | ||
| + | </ | ||
| + | ++++ | ||
| ===== Idem avec capteur de présence (série) ===== | ===== Idem avec capteur de présence (série) ===== | ||
|   * Fichiers : {{: |   * Fichiers : {{: | ||