Outils pour utilisateurs

Outils du site


loop_vinyl

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édentesRévision précédente
Dernière révisionLes deux révisions suivantes
loop_vinyl [2018/10/11 15:07] guillaumeloop_vinyl [2018/10/11 15:12] – [Un peu de code] guillaume
Ligne 46: Ligne 46:
  
 Voià le code arduino basé sur [[http://playground.arduino.cc/Code/Stopwatch|StopWatch]] de Paul Badger. Merci à Olivier et Ludo pour leur aide précieuse... Voià le code arduino basé sur [[http://playground.arduino.cc/Code/Stopwatch|StopWatch]] de Paul Badger. Merci à Olivier et Ludo pour leur aide précieuse...
 +<code>
   /* StopWatch   /* StopWatch
   * Paul Badger 2008   * Paul Badger 2008
Ligne 54: Ligne 54:
   * Physical setup: momentary switch connected to pin 4, other side connected to ground   * Physical setup: momentary switch connected to pin 4, other side connected to ground
   * LED with series resistor between pin 13 and ground   * LED with series resistor between pin 13 and ground
-\\+  
   LOOP VINYL   LOOP VINYL
   Commande vitesse PWM   Commande vitesse PWM
   potentiomètre en A0 -> Analog input    potentiomètre en A0 -> Analog input 
-\\+  
   Commande moteur -> 3 pin EA, I1, I2   Commande moteur -> 3 pin EA, I1, I2
   EA -> vitesse - valeur potentiomètre pwmOUT pin11   EA -> vitesse - valeur potentiomètre pwmOUT pin11
   I1 -> direction - digitalOUT8   I1 -> direction - digitalOUT8
   I2 -> direction - digitalOUT9   I2 -> direction - digitalOUT9
-\\+  
   Changement de sens selon temporisation   Changement de sens selon temporisation
   bouton loop -> digitalIn3   bouton loop -> digitalIn3
-\\ 
   bouton Play -> digitalIn 6   bouton Play -> digitalIn 6
   bouton Stop -> digitalIn 5   bouton Stop -> digitalIn 5
   bouton Rew -> digitalIn 4   bouton Rew -> digitalIn 4
-\\ +   
-\\ +   */ 
-  */ + 
-\\ +
-\\+
   int pinPot = 0 ;                //potentiomètre réglage vitesse   int pinPot = 0 ;                //potentiomètre réglage vitesse
-\\+
   #define ledPin  12                 // LED connected to digital pin 13   #define ledPin  12                 // LED connected to digital pin 13
   #define buttonPin 3                 // button loop   #define buttonPin 3                 // button loop
-\\+
   int value = LOW;                    // previous value of the LED   int value = LOW;                    // previous value of the LED
   int buttonState;                    // variable to store button state   int buttonState;                    // variable to store button state
Ligne 90: Ligne 88:
   int fractional;                     // variable used to store fractional part of time   int fractional;                     // variable used to store fractional part of time
   boolean avant;     boolean avant;  
-\\+
   void setup()   void setup()
   {   {
Ligne 101: Ligne 99:
     pinMode( 9 , OUTPUT); //commande moteur I2 (sens rotation)     pinMode( 9 , OUTPUT); //commande moteur I2 (sens rotation)
     pinMode( 11 , OUTPUT); //commande moteur vitesse (pwm)        pinMode( 11 , OUTPUT); //commande moteur vitesse (pwm)   
-\\+
     //pinMode(buttonPin, INPUT);       // not really necessary, pins default to INPUT anyway     //pinMode(buttonPin, INPUT);       // not really necessary, pins default to INPUT anyway
     digitalWrite(3, HIGH);   // turn on pullup resistors. Wire button so that press shorts pin to ground.     digitalWrite(3, HIGH);   // turn on pullup resistors. Wire button so that press shorts pin to ground.
          
     avant = true;     avant = true;
-\\+
   }   }
-\\+
   void loop()   void loop()
   {   {
Ligne 117: Ligne 115:
     stopage();     stopage();
     reverse();      reverse(); 
-\\+
     pinPot = analogRead(0) ; //lecture valeur potentiomètre Vitesse     pinPot = analogRead(0) ; //lecture valeur potentiomètre Vitesse
     analogWrite(11 , analogRead(0)); //valeur vitesse pwm       analogWrite(11 , analogRead(0)); //valeur vitesse pwm  
Ligne 124: Ligne 122:
     if  (elapsedTime != 0) {     if  (elapsedTime != 0) {
       lectureLoopage();       lectureLoopage();
-\\+
     }     }
-\\+
   }   }
-\\+
   void play()   void play()
   {   {
Ligne 137: Ligne 135:
       elapsedTime = 0;       elapsedTime = 0;
     }     }
-\\+
   }   }
-\\+
   void stopage()   void stopage()
   {   {
Ligne 149: Ligne 147:
     }     }
   }   }
-\\+  
   void reverse()   void reverse()
   {   {
Ligne 159: Ligne 157:
     }     }
   }   }
-\\ + 
-\\+
   void loopage()   void loopage()
   {   {
     // check for button press     // check for button press
     buttonState = digitalRead(3);                   // read the button state and store      buttonState = digitalRead(3);                   // read the button state and store 
-\\ +
-\\+
     if (buttonState == LOW && lastButtonState == HIGH  &&  blinking == false){     // check for a high to low transition     if (buttonState == LOW && lastButtonState == HIGH  &&  blinking == false){     // check for a high to low transition
       // if true then found a new button press while clock is not running - start the clock       // if true then found a new button press while clock is not running - start the clock
-\\+
       startTime = millis();                                   // store the start time       startTime = millis();                                   // store the start time
       blinking = true;                                     // turn on blinking while timing       blinking = true;                                     // turn on blinking while timing
       delay(5);                                               // short delay to debounce switch       delay(5);                                               // short delay to debounce switch
       lastButtonState = buttonState;                          // store buttonState in lastButtonState, to compare next time       lastButtonState = buttonState;                          // store buttonState in lastButtonState, to compare next time
-\\+
     }     }
-\\+
     else if (buttonState == LOW && lastButtonState == HIGH && blinking == true){     // check for a high to low transition     else if (buttonState == LOW && lastButtonState == HIGH && blinking == true){     // check for a high to low transition
       // if true then found a new button press while clock is running - stop the clock and report       // if true then found a new button press while clock is running - stop the clock and report
-\\+
       elapsedTime =   millis() - startTime;              // store elapsed time       elapsedTime =   millis() - startTime;              // store elapsed time
       blinking = false;                                  // turn off blinking, all done timing       blinking = false;                                  // turn off blinking, all done timing
Ligne 187: Ligne 184:
       digitalWrite( 8 , HIGH );       digitalWrite( 8 , HIGH );
       digitalWrite( 9 , LOW );       digitalWrite( 9 , LOW );
-\\+
       // store buttonState in lastButtonState, to compare next time       // store buttonState in lastButtonState, to compare next time
-\\+
       // routine to report elapsed time       // routine to report elapsed time
       Serial.print( (int)(elapsedTime / 1000L));         // divide by 1000 to convert to seconds - then cast to an int to print       Serial.print( (int)(elapsedTime / 1000L));         // divide by 1000 to convert to seconds - then cast to an int to print
-\\ + 
-\\+
       //Serial.print(".");                             // print decimal point       //Serial.print(".");                             // print decimal point
-\\+
         // use modulo operator to get fractional part of time          // use modulo operator to get fractional part of time 
       fractional = (int)(elapsedTime % 1000L);       fractional = (int)(elapsedTime % 1000L);
-\\+
       // pad in leading zeros - wouldn't it be nice if       // pad in leading zeros - wouldn't it be nice if
       // Arduino language had a flag for this? :)       // Arduino language had a flag for this? :)
Ligne 207: Ligne 204:
       else if (fractional < 100)       else if (fractional < 100)
         Serial.print("0");        // add one zero         Serial.print("0");        // add one zero
-\\+
       Serial.println(fractional);  // print fractional part of time       Serial.println(fractional);  // print fractional part of time
-\\+
     }     }
-\\+
     else{     else{
       lastButtonState = buttonState;                         // store buttonState in lastButtonState, to compare next time       lastButtonState = buttonState;                         // store buttonState in lastButtonState, to compare next time
     }     }
-\\+
     // blink routine - blink the LED while timing     // blink routine - blink the LED while timing
     // check to see if it's time to blink the LED; that is, the difference     // check to see if it's time to blink the LED; that is, the difference
     // between the current time and last time we blinked the LED is larger than     // between the current time and last time we blinked the LED is larger than
     // the interval at which we want to blink the LED.     // the interval at which we want to blink the LED.
-\\+
     if ( (millis() - previousMillis > interval) ) {     if ( (millis() - previousMillis > interval) ) {
-\\+
       if (blinking == true){       if (blinking == true){
         previousMillis = millis();                         // remember the last time we blinked the LED         previousMillis = millis();                         // remember the last time we blinked the LED
-\\+
         // if the LED is off turn it on and vice-versa.         // if the LED is off turn it on and vice-versa.
         if (value == LOW)         if (value == LOW)
Ligne 237: Ligne 234:
       }       }
     }     }
-\\+
   }   }
-\\+
   void lectureLoopage() {   void lectureLoopage() {
-\\+
     if (elapsedTime <= millis() - startTimeLoop) {     if (elapsedTime <= millis() - startTimeLoop) {
-\\+
       startTimeLoop = millis();       startTimeLoop = millis();
       avant = !avant;       avant = !avant;
Ligne 260: Ligne 257:
       }       }
            
-\\ 
     }     }
   }   }
 +</code>
  
 {{tag>faire_du_bruit}} {{tag>faire_du_bruit}}
loop_vinyl.txt · Dernière modification : 2020/10/29 13:58 de serge