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 [2015/03/30 14:24] resonance  | 
                
                    projets:chimeres-orchestra:code-arduino:accueil [2017/02/10 17:46] (Version actuelle) resonance [Arduino Chimères OSC]  | 
            ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Code Arduino ====== | ====== Code Arduino ====== | ||
| + | A tester ([[http:// | ||
| + |   * [[http:// | ||
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | for arduino in / | ||
| + | do | ||
| + | ino upload -m micro -p $arduino | ||
| + | sleep 1 | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== 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) ===== | ||
| + |   * Fichiers : {{: | ||
| + | |||
| + | |||
| + | ++++ chimeres_capteur | | ||
| + | <code cpp> | ||
| + | // Chimères Orchestra | ||
| + | // Raspberry Pi > Pd > Serial > Arduino MEGA > MOSFETS | ||
| + | // Digital sensor to activate | ||
| + | |||
| + | #include " | ||
| + | |||
| + | // ---- CONFIGURATIONS ---- // | ||
| + | int pins[] = {3, | ||
| + | int time_max = 150; | ||
| + | boolean DEBUG = false; | ||
| + | |||
| + | // ---- VARIABLES --------- // | ||
| + | int id, pwm, time; | ||
| + | const int nb = 6; | ||
| + | PwmMotor motors[nb]; | ||
| + | unsigned long current = 0; | ||
| + | |||
| + | unsigned long button_interval = 50; | ||
| + | unsigned long button_previous = 0; | ||
| + | int button_state = 0; | ||
| + | int button_last_state = 0; | ||
| + | int button_pin = 2; // | ||
| + | |||
| + | |||
| + | // ---- PROGRAM ----------- // | ||
| + | void setup() { | ||
| + |   Serial.begin(38400); | ||
| + | for (int i; i < nb; i++) { | ||
| + |       | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | current = millis(); | ||
| + |    | ||
| + | // Sensor | ||
| + | if(current - button_previous > button_interval) { // sampling | ||
| + |       button_previous = current;  | ||
| + |       button_state = digitalRead(button_pin); | ||
| + | if (button_state != button_last_state) { // if the state has changed | ||
| + |         Serial.println(button_state); | ||
| + | } | ||
| + |       button_last_state = button_state; | ||
| + | } | ||
| + | |||
| + | // ON | ||
| + | while (Serial.available()) { | ||
| + |      id = Serial.parseInt();  | ||
| + |      pwm = Serial.parseInt(); | ||
| + |      time = Serial.parseInt(); | ||
| + |      if (Serial.read() == ' | ||
| + |        if( motors[id].isOn() == false )  motors[id].on(current, | ||
| + | } | ||
| + | } | ||
| + |    | ||
| + | // OFF | ||
| + | for (int i; i < nb; i++) { | ||
| + |      if( motors[i].isOn() ) motors[i].off(current); | ||
| + | } | ||
| + |    | ||
| + | delay(5); | ||
| + | } | ||
| + | </ | ||
| + | ++++ | ||
| + | ===== Serial / Arduino / PwmMotor library ===== | ||
| + |   * Fichiers : {{: | ||
| + | |||
| + | ++++ chimeres_serial_interval_pwm | | ||
| + | <code cpp> | ||
| + | // Chimères Orchestra | ||
| + | // Pd > Serial > Arduino MEGA > MOSFETS | ||
| + | |||
| + | #include " | ||
| + | |||
| + | // ---- CONFIGURATIONS ---- // | ||
| + | int pins[] = {2, | ||
| + | int time_max = 150; | ||
| + | boolean DEBUG = false; | ||
| + | |||
| + | // ---- VARIABLES --------- // | ||
| + | int id, pwm, time; | ||
| + | const int nb = 6; | ||
| + | PwmMotor motors[nb]; | ||
| + | unsigned long current = 0; | ||
| + | |||
| + | // ---- PROGRAM ----------- // | ||
| + | void setup() { | ||
| + |   Serial.begin(38400); | ||
| + | for (int i; i < nb; i++) { | ||
| + |       | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | current = millis(); | ||
| + |    | ||
| + | // ON | ||
| + | while (Serial.available()) { | ||
| + |      id = Serial.parseInt();  | ||
| + |      pwm = Serial.parseInt(); | ||
| + |      time = Serial.parseInt(); | ||
| + |      if (Serial.read() == ' | ||
| + |        if( !motors[id].isOn() )  motors[id].on(current, | ||
| + | } | ||
| + | } | ||
| + |    | ||
| + | // OFF | ||
| + | for (int i; i < nb; i++) { | ||
| + |      if( motors[i].isOn() ) motors[i].off(current); | ||
| + | } | ||
| + |    | ||
| + | delay(1); | ||
| + | } | ||
| + | </ | ||
| + | ++++ | ||
| + | |||
| + | ++++ PwmMotor.h | | ||
| + | <code cpp> | ||
| + | #ifndef PWMMOTOR_H | ||
| + | #define PWMMOTOR_H | ||
| + | |||
| + | #include < | ||
| + | |||
| + | class PwmMotor | ||
| + | { | ||
| + | public: | ||
| + | 	PwmMotor(); | ||
| + | 	~PwmMotor(); | ||
| + | void init(int _pin, int _time_max, boolean _debug); | ||
| + | void on(unsigned long _current, int _pwm, int _time); | ||
| + | void off(unsigned long _current); | ||
| + | boolean isOn(); | ||
| + | |||
| + | private: | ||
| + | boolean debug; | ||
| + | boolean state; | ||
| + | unsigned long last; | ||
| + | 	long time_on;  | ||
| + | 	int time_on_max; | ||
| + | int pin; | ||
| + | }; | ||
| + | |||
| + | #endif | ||
| + | </ | ||
| + | ++++ | ||
| + | |||
| + | |||
| + | ++++ PwmMotor.cpp | | ||
| + | <code cpp> | ||
| + | #include " | ||
| + | |||
| + | PwmMotor:: | ||
| + | state = false; | ||
| + | last = 0; | ||
| + | time_on = 150; | ||
| + | debug = false; | ||
| + | } | ||
| + | |||
| + | PwmMotor:: | ||
| + | |||
| + | void PwmMotor:: | ||
| + | debug = _debug; | ||
| + | time_on_max = _time_max; | ||
| + | pin = _pin; | ||
| + |       | ||
| + |       | ||
| + | } | ||
| + | |||
| + | boolean PwmMotor:: | ||
| + |         return state;  | ||
| + | } | ||
| + | |||
| + | void PwmMotor:: | ||
| + | if( _current - last >= (time_on + 10) ) { // !state && | ||
| + | state = true; | ||
| + | last = _current; | ||
| + | 		time_on = constrain(_time, | ||
| + |                 if (debug) Serial.println(" | ||
| + | 		analogWrite(pin, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void PwmMotor:: | ||
| + | if( _current - last >= time_on ) { // state && | ||
| + | state = false; | ||
| + | 	    	analogWrite(pin, | ||
| + |                 if (debug) Serial.println(" | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | ++++ | ||
| ===== UDP / OSC ===== | ===== UDP / OSC ===== | ||
| ++++ Code UDP OSC | | ++++ Code UDP OSC | | ||
| Ligne 233: | Ligne 561: | ||
| } | } | ||
| } | } | ||
| + | } | ||
| + | </ | ||
| + | ++++ | ||
| + | |||
| + | |||
| + | ===== Dublin 06/2012 ===== | ||
| + |   * Code répéteur autonome (avec piezo)  | ||
| + |   * Fichiers : {{: | ||
| + | |||
| + | ++++ Code autonome | | ||
| + | <code cpp> | ||
| + | // Not tested ! | ||
| + | // TO DO : verify input sensor and automatic, verify sequences modes | ||
| + | |||
| + | // ******************************************* // | ||
| + | // Chimères Orchestra | ||
| + | // Robotic drums in public space | ||
| + | // In the "Hack the city" exhibition, Science Gallery, Dublin | ||
| + | // http:// | ||
| + | // Jérome Abel - 22/06/2012 | ||
| + | // GNU/GPL v3 | ||
| + | // ******************************************* // | ||
| + | |||
| + | // LIEU | ||
| + | // 0 : Gallery, 1 : Meeting house square (left side), 2 : Meeting house square (right side) | ||
| + | int LOCATION = 0; | ||
| + | |||
| + | // SOLENOIDS | ||
| + | const int NUMBER = 5; | ||
| + | int solenoids_pins [][NUMBER] = | ||
| + | { | ||
| + |   {5, | ||
| + |   {4, | ||
| + |   {4, | ||
| + | }; | ||
| + | |||
| + | // DEBUG | ||
| + | boolean DEBUG = true; | ||
| + | |||
| + | // AUTOMATIC TIME | ||
| + | //int auto_interval = 15*60000; // 15 minutes | ||
| + | int auto_interval = 20000; // 15 minutes | ||
| + | int auto_duration = 5000; | ||
| + | |||
| + | // PIEZO | ||
| + | const int p_threshold = 80; | ||
| + | const int p_debounce = 100; // antirebond | ||
| + | const int p_interval = 12000; // after 8 seconds, rhythms stop | ||
| + | const int p_interval_min = 8000; // minimum | ||
| + | const int p_interval_max = 25000; // maximum | ||
| + | |||
| + | const int p_declenchement_seq = 8; // number of hits to start rhythms  | ||
| + | const int p_pin = A0; // sensor pin | ||
| + | |||
| + | // ATTACK TIME | ||
| + | int on = 35; // default setting | ||
| + | int s_attack_on = on; // default setting | ||
| + | int s_attack_on_min = 30; | ||
| + | int s_attack_on_max = 45; | ||
| + | |||
| + | int off = 90;// default setting | ||
| + | int s_attack_off = off ; | ||
| + | int s_attack_off_min = 80; | ||
| + | int s_attack_off_max = 110; | ||
| + | |||
| + | int seq_interval = s_attack_on + s_attack_off; | ||
| + | |||
| + | // ******************* RHYTHMS ********************* // | ||
| + | |||
| + | // SEQUENCES  | ||
| + | boolean seq[][4] = | ||
| + | { | ||
| + | {0,0,0,0}, // 0 | ||
| + | {1,0,0,0}, // 1 | ||
| + | {0,1,0,0}, // 2 | ||
| + | {0,0,1,0}, // 3 | ||
| + | {0,0,0,1}, // 4 | ||
| + | {1,1,0,0}, // 5 | ||
| + | {1,0,1,0}, // 6 | ||
| + | {1,0,0,1}, // 7 | ||
| + | {0,1,1,0}, // 8 | ||
| + | {0,1,0,1}, // 9 | ||
| + | {0,0,1,1}, // 10 | ||
| + | {1,1,1,0}, // 11 | ||
| + | {0,1,1,1}, // 12 | ||
| + | {1, | ||
| + | }; | ||
| + | |||
| + | int patterns[][4] = | ||
| + | { | ||
| + | {5,5,5,5}, //0 | ||
| + | {4,4,4,12}, | ||
| + | {0,1,1,1}, | ||
| + | {1,1,1,1}, | ||
| + | {1,1,1,2}, | ||
| + | {2, | ||
| + | {3, | ||
| + | {4,4,4,4}, | ||
| + | {7,5,5,5}, | ||
| + | {5,5,5,0}, | ||
| + | {3,5,3,5}, | ||
| + | {1,7,1,7}, | ||
| + | {0, | ||
| + | {4,5,4,0}, | ||
| + | {9,9,4,9}, | ||
| + | {2,6,6,2}, | ||
| + | {7, | ||
| + | {12, | ||
| + | {13, | ||
| + | |||
| + | // EXTRA | ||
| + | {12,0,0,0}, // 19 | ||
| + | {0,0,0,5}, | ||
| + | {0,0,0,9}, | ||
| + | {2,5,0,0}, | ||
| + | {0,3,0,3}, | ||
| + | {3,0,5,0}, | ||
| + | {6,6,0,0}, | ||
| + | {0,0,0,13}, | ||
| + | {0,0,0,8}, | ||
| + | {0,0,0,11}, | ||
| + | {0, | ||
| + | {0, | ||
| + | {0, | ||
| + | {0,1,1,0}, | ||
| + | {2, | ||
| + | {0, | ||
| + | {1,0,11,0}, | ||
| + | {0,13,11,0} //36 | ||
| + | }; | ||
| + | // *************************************************** // | ||
| + | int seq_counter = 0; | ||
| + | int seq_counter_pattern = 0; | ||
| + | |||
| + | int seq_tempo = 0; | ||
| + | int solenoids_seq[6]; | ||
| + | boolean auto_sequence = false; | ||
| + | int sequence_mode = 0; | ||
| + | |||
| + | // TIME | ||
| + | unsigned long currentMillis = 0; | ||
| + | unsigned long previousMillis = 0; | ||
| + | int interval = 1000; | ||
| + | unsigned long auto_time = 0; | ||
| + | |||
| + | // TAP TEMPO | ||
| + | unsigned long p_taptempo = 0; | ||
| + | float p_taptempo_average = 0; | ||
| + | float p_taptempo_total = 0; | ||
| + | float p_last_taptempo = 0; | ||
| + | |||
| + | // PIEZO | ||
| + | int p_reading = 0; | ||
| + | boolean p_state = false; | ||
| + | boolean p_state_last = false; | ||
| + | long p_time = 0; | ||
| + | int p_counter = 0; | ||
| + | long p_counter_time = 0; | ||
| + | |||
| + | // SEQUENCE | ||
| + | long alternate_time = 0; | ||
| + | int random_seq = random(24, | ||
| + | int random_attack_time = random(16, | ||
| + | |||
| + | |||
| + | // ****************** getPiezo() ************************* // | ||
| + | boolean getPiezo(){ | ||
| + |   p_reading = analogRead(p_pin);  | ||
| + |   if (p_reading >= p_threshold && currentMillis - p_time >= p_debounce)  | ||
| + | { | ||
| + |     p_counter++;  | ||
| + |      | ||
| + |     if (DEBUG)  | ||
| + | { | ||
| + |       Serial.println(" | ||
| + |       Serial.println(" | ||
| + |       Serial.print(" | ||
| + |       Serial.println(p_counter); | ||
| + | } | ||
| + |      | ||
| + | if (p_counter > 1) | ||
| + | { | ||
| + | p_last_taptempo = p_taptempo; | ||
| + | p_taptempo = currentMillis - p_time; | ||
| + |       if (DEBUG)  | ||
| + | { | ||
| + |           | ||
| + |           | ||
| + | } | ||
| + |       p_taptempo_total = (int)p_taptempo + (int)p_last_taptempo; | ||
| + | if (p_counter > 2) | ||
| + | { | ||
| + | p_taptempo_average = p_taptempo_total / 2 ; | ||
| + | if (DEBUG) | ||
| + | { | ||
| + |           Serial.print(" | ||
| + |           Serial.println(p_taptempo_average); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + |      | ||
| + |       | ||
| + |       | ||
| + | } | ||
| + | else { return false;} | ||
| + | } | ||
| + | |||
| + | // ***************** single_attack() **************** // | ||
| + | void single_attack(int pin){ | ||
| + |   | ||
| + |   | ||
| + |   | ||
| + |   | ||
| + | } | ||
| + | |||
| + | // ****************** chenillard() ****************** // | ||
| + | void chenillard(){   | ||
| + |   if (DEBUG) Serial.println(" | ||
| + | for (int i = 0; i < NUMBER ; i++) { | ||
| + |     single_attack(solenoids_pins[LOCATION][i]); | ||
| + | delay(250); | ||
| + | } | ||
| + | } | ||
| + |    | ||
| + | // ****************** SETUP ************************* // | ||
| + | void setup() { | ||
| + |   randomSeed(analogRead(1)); | ||
| + |    | ||
| + |   Serial.begin(9600); | ||
| + | for (int i = 0; i < NUMBER ; i++) { | ||
| + |     pinMode(solenoids_pins[LOCATION][i], | ||
| + | solenoids_seq[i] = random(13); | ||
| + | } | ||
| + |   delay(1000); | ||
| + |   chenillard(); | ||
| + | } | ||
| + | |||
| + | // ****************** LOOP ************************* // | ||
| + | void loop() {   | ||
| + | currentMillis = millis(); | ||
| + |    | ||
| + | // start automatic | ||
| + | if (currentMillis - auto_time > auto_interval){ | ||
| + | auto_sequence = true; | ||
| + |     sequence_mode = 1;// | ||
| + |     auto_time = currentMillis; | ||
| + |     seq_counter_pattern=0; | ||
| + |     seq_counter=0; | ||
| + |     if (DEBUG) Serial.println(" | ||
| + | } | ||
| + |    | ||
| + | // stop automatic | ||
| + | if (auto_sequence && currentMillis - auto_time > auto_duration){ | ||
| + | auto_sequence = false; | ||
| + | |||
| + |     if (DEBUG) Serial.println(" | ||
| + | } | ||
| + | |||
| + | // getPiezo | ||
| + | // if (!auto_sequence) p_state = getPiezo(); | ||
| + | |||
| + | // p_interval, counter | ||
| + | if (!auto_sequence && currentMillis - p_time > p_interval ){ | ||
| + |     p_counter=0; | ||
| + | p_taptempo_total = 0; | ||
| + | p_taptempo_average = 0; | ||
| + |     seq_counter=0; | ||
| + |     seq_counter_pattern=0; | ||
| + | } | ||
| + |    | ||
| + | // single_attack with the piezo | ||
| + |   if (p_counter > 0 && p_counter < p_declenchement_seq && p_state)  | ||
| + | { | ||
| + |     int pin = solenoids_pins[LOCATION][random(NUMBER)]; | ||
| + | if (DEBUG) { | ||
| + |       Serial.print(" | ||
| + |       Serial.println(pin); | ||
| + | } | ||
| + |     single_attack(pin); | ||
| + | } | ||
| + |    | ||
| + |   // start rhythms with a " | ||
| + |   if (p_counter == p_declenchement_seq)  | ||
| + | { | ||
| + |     chenillard(); | ||
| + | sequence_mode = random(2); | ||
| + | } | ||
| + |    | ||
| + | if (p_counter >= p_declenchement_seq || auto_sequence ) | ||
| + | { | ||
| + | if (!auto_sequence) seq_tempo = seq_interval * (p_taptempo_average / 1000); // change the tempo with piezo tap tempo | ||
| + |     else seq_tempo = seq_interval; | ||
| + |      | ||
| + | if (currentMillis - previousMillis > seq_tempo ) | ||
| + | { | ||
| + | if (DEBUG) | ||
| + | { | ||
| + |         Serial.print(" | ||
| + |         Serial.println(seq_counter); | ||
| + | } | ||
| + |      | ||
| + | // random attack time on/off every [8-32] steps | ||
| + | if (seq_counter % random_attack_time == 0) | ||
| + | { | ||
| + |         | ||
| + | if (random(100) > 60) { // 40% of random | ||
| + |           | ||
| + |           | ||
| + | } | ||
| + | else { | ||
| + |           | ||
| + |           | ||
| + | } | ||
| + |         | ||
| + | } | ||
| + |            | ||
| + | // SEQUENCE MODE 0 (random) | ||
| + | if (sequence_mode == 0) | ||
| + | { | ||
| + | // random sequences every [24-32] steps | ||
| + | if (seq_counter % random_seq == 0) | ||
| + | { | ||
| + |           | ||
| + | for (int i = random(2); i < random(4,6) ; i++) | ||
| + | { | ||
| + |             | ||
| + | } | ||
| + | } | ||
| + |      | ||
| + | // ON : sequences for each pins | ||
| + | for (int i = 0; i < NUMBER ; i++) { | ||
| + |           digitalWrite(solenoids_pins[LOCATION][i], | ||
| + |         }     | ||
| + |         delay(s_attack_on); | ||
| + | } | ||
| + |      | ||
| + | // SEQUENCE MODE 1 (less random, more human) | ||
| + | if (sequence_mode == 1) | ||
| + | { | ||
| + | // random patterns every [24-32] steps | ||
| + | if (seq_counter % random_seq == 0) | ||
| + | { | ||
| + |           | ||
| + | for (int i = random(2); i < random(4,6) ; i++) | ||
| + | { | ||
| + | int choice = random(3); | ||
| + | if (choice == 0) solenoids_seq[i] = random(19); | ||
| + |            else if (choice == 1) solenoids_seq[i] = random(19, | ||
| + | } | ||
| + | } | ||
| + |          | ||
| + | // ON : sequences for each pins | ||
| + | for (int i = 0; i < NUMBER ; i++) | ||
| + | { | ||
| + |           digitalWrite(solenoids_pins[LOCATION][i], | ||
| + |           if (DEBUG)  | ||
| + | { | ||
| + |             | ||
| + |             | ||
| + |             | ||
| + |             | ||
| + |             | ||
| + |             | ||
| + |             | ||
| + |             | ||
| + |             | ||
| + |             | ||
| + |             | ||
| + | } | ||
| + |            | ||
| + | if (seq_counter % 4 == 0) | ||
| + | { | ||
| + |             seq_counter_pattern++; | ||
| + | } | ||
| + |         }     | ||
| + |         delay(s_attack_on);  | ||
| + | } | ||
| + |      | ||
| + | // OFF : all off | ||
| + | for (int i = 0; i < NUMBER ; i++) { | ||
| + |         digitalWrite(solenoids_pins[LOCATION][i], | ||
| + | } | ||
| + |       delay(s_attack_off);   | ||
| + |      | ||
| + |       seq_counter++; | ||
| + |        | ||
| + |       previousMillis = currentMillis; | ||
| + | } // end seq_tempo | ||
| + | } // end start rythms | ||
| + |    | ||
| + |   delay(5);  | ||
| } | } | ||
| </ | </ | ||
| ++++ | ++++ | ||