diff options
| -rw-r--r-- | notes_arduino.rst | 182 | ||||
| -rw-r--r-- | resources/admonitions.tex | 2 | ||||
| -rw-r--r-- | resources/figures.tex | 11 | 
3 files changed, 111 insertions, 84 deletions
| diff --git a/notes_arduino.rst b/notes_arduino.rst index 4cf2026..d0d30db 100644 --- a/notes_arduino.rst +++ b/notes_arduino.rst @@ -11,6 +11,9 @@  .. sectnum::    :depth: 2 +.. role:: raw-latex(raw) +   :format: latex +  ****************  La carte Arduino  **************** @@ -58,6 +61,7 @@ L'initialisation s'exécute seulement au démarrage du programme sur la carte  .. code-block:: arduino    :number-lines: 9 +  :class: program    // the setup routine runs once when you press reset:    void setup() { @@ -81,6 +85,7 @@ indéfiniment, tant que la carte sera sous tension.  .. code-block::  arduino    :number-lines:  15 +  :class: program    // the loop routine runs over and over again forever:    void loop() { @@ -114,39 +119,40 @@ avec la valeur `LOW`, suivi d'une nouvelle pause d'une seconde.    digital signifie *numérique*. Le terme indique une valeur que l'on peut    exprimer en nombre entier (1, 2, 3…). -Le programme complet --------------------- -  .. sidebar:: Chargement    Ce programme est disponible dans l'environnement Arduino dans les exemples :    Basic / Blink -.. code-block:: arduino -  /* -    Blink -    Turns on an LED on for one second, then off for one -    second, repeatedly. +.. admonition:: Clignotement d'une |led| +  :class: floatprogram -    This example code is in the public domain. -   */ +    .. code-block:: arduino -  // the setup routine runs once when you press reset: -  void setup() { -    // initialize the digital pin as an output. -    pinMode(13, OUTPUT); -  } +      /* +        Blink +        Turns on an LED on for one second, then off for one +        second, repeatedly. -  // the loop routine runs over and over again forever: -  void loop() { -    // turn the LED on (HIGH is the voltage level) -    digitalWrite(13, HIGH); -    delay(1000);               // wait for a second -    digitalWrite(13, LOW); -    // turn the LED off by making the voltage LOW -    delay(1000);               // wait for a second -  } +        This example code is in the public domain. +       */ + +      // the setup routine runs once when you press reset: +      void setup() { +        // initialize the digital pin as an output. +        pinMode(13, OUTPUT); +      } + +      // the loop routine runs over and over again forever: +      void loop() { +        // turn the LED on (HIGH is the voltage level) +        digitalWrite(13, HIGH); +        delay(1000);               // wait for a second +        digitalWrite(13, LOW); +        // turn the LED off by making the voltage LOW +        delay(1000);               // wait for a second +      }  Utiliser une led externe  ======================== @@ -345,9 +351,6 @@ sur chacun de ses ports, en envoyant une valeur comprise entre `0` et `255`.    Avec un multimètre, mesurer la tension en sortie de la borne en fonction de    diverses valeurs. -Programme ---------- -  .. sidebar:: Ressource limitée !    Cette capacité à contrôler la tension de sortie est très intéressante (par @@ -355,41 +358,44 @@ Programme    limitée à 6 bornes seulement. Il vaut mieux les réserver quand nous avons    besoin d'une sortie analogique. -.. code-block:: arduino +.. admonition:: Luminosité +  :class: floatprogram -  // Fade +    .. code-block:: arduino -  // This example shows how to fade an LED on pin 9 -  // using the analogWrite() function. +      // Fade -  // This example code is in the public domain. +      // This example shows how to fade an LED on pin 9 +      // using the analogWrite() function. -  int led = 9;        // the pin that the LED is attached to -  int brightness = 0; // how bright the LED is -  int fadeAmount = 5; // how many points to fade the LED by +      // This example code is in the public domain. -  // the setup routine runs once when you press reset: -  void setup() { -    // declare pin 9 to be an output: -    pinMode(led, OUTPUT); -  } +      int led = 9;        // the pin that the LED is attached to +      int brightness = 0; // how bright the LED is +      int fadeAmount = 5; // how many points to fade the LED by -  // the loop routine runs over and over again forever: -  void loop() { -    // set the brightness of pin 9: -    analogWrite(led, brightness); - -    // change the brightness for next time through the loop: -    brightness = brightness + fadeAmount; +      // the setup routine runs once when you press reset: +      void setup() { +        // declare pin 9 to be an output: +        pinMode(led, OUTPUT); +      } -    // reverse the direction of the fading -    // at the ends of the fade: -    if (brightness == 0 || brightness == 255) { -      fadeAmount = -fadeAmount ; -    } -    // wait for 30 milliseconds to see the dimming effect -    delay(30); -  } +      // the loop routine runs over and over again forever: +      void loop() { +        // set the brightness of pin 9: +        analogWrite(led, brightness); + +        // change the brightness for next time through the loop: +        brightness = brightness + fadeAmount; + +        // reverse the direction of the fading +        // at the ends of the fade: +        if (brightness == 0 || brightness == 255) { +          fadeAmount = -fadeAmount ; +        } +        // wait for 30 milliseconds to see the dimming effect +        delay(30); +      }  Générer du son @@ -434,6 +440,7 @@ n'est donc pas nécessaire de réserver une sortie analogique pour le buzzer.)    carte Arduino un outil `hi-fi` :    .. code-block:: arduino +    :class: program      void tone(int targetPin, long frequency, long length) {        // calculate the delay value between transitions @@ -462,6 +469,7 @@ Par exemple, en connectant le buzzer sur la broche `8`, l'instruction suivante  permettra de jouer un  *la* pendant une seconde :  .. code-block:: arduino +  :class: program    tone(8, 440, 1000); @@ -633,6 +641,7 @@ définir une fonction `runMotor` qui prendra trois paramètres :  :speed:     La vitesse de rotation, cette valeur peut aller de `0` à `255`  .. code-block:: arduino +  :class: program    void runMotor(int motor, int direction, int speed) {      // … @@ -906,8 +915,11 @@ valeurs :    `analogRead`, la valeur de la résistance calculée, et l'intensité qui    traverse les composants. -.. include:: content/ohm.py -  :code: python +.. admonition:: Simulateur en python +  :class: floatprogram + +    .. include:: content/ohm.py +      :code: python  .. raw:: latex @@ -965,29 +977,28 @@ résultat sur la console.      appellée. En effet, par défaut, toutes les bornes du microcontrolleur sont      déclarées en mode `OUTPUT`. -.. code-block:: arduino - -  // La résistance r2 doit être connue et -  // renseignée dans le programme -  int r2 = ...; - -  void setup() { -    Serial.begin(9600); -  } +.. admonition:: Ohmmètre +  :class: floatprogram -  void loop() { +    .. code-block:: arduino -    int r1 = r2 * ((1023 / (float)analogRead(A0)) - 1); +      // La résistance r2 doit être connue et +      // renseignée dans le programme +      int r2 = ...; -    Serial.print("R1: "); -    Serial.println(r1); +      void setup() { +        Serial.begin(9600); +      } -    delay(1000);// wait for a second -  } +      void loop() { -.. [#] https://www.arduino.cc/en/Serial/Print +        int r1 = r2 * ((1023 / (float)analogRead(A0)) - 1); +        Serial.print("R1: "); +        Serial.println(r1); +        delay(1000);// wait for a second +      }  .. note:: @@ -999,6 +1010,8 @@ résultat sur la console.    que d'envoyer l'information vers l'ordinateur : nous aurons ainsi un ohmmètre    autonome ! +.. [#] https://www.arduino.cc/en/Serial/Print +  Capteur de proximité infrarouge  =============================== @@ -1063,21 +1076,24 @@ Exemple  Ce programme lit l'entrée sur la broche `A0` et allume une |led| si un objet  est détecté à proximité (±20 |cm|) : -.. code-block:: arduino +.. admonition:: Détecteur d'objet +  :class: floatprogram +    .. code-block:: arduino -  int ledPin = 9;    // LED connected to digital pin 9 -  void setup()  {} +      int ledPin = 9;    // LED connected to digital pin 9 -  void loop()  { -    int sensorValue = analogRead(A0); -    if (sensorValue < 220) -      sensorValue = 0; +      void setup()  {} -    analogWrite(ledPin, sensorValue >> 2); -    delay(200);            // delay 200 milliseconds -  } +      void loop()  { +        int sensorValue = analogRead(A0); +        if (sensorValue < 220) +          sensorValue = 0; + +        analogWrite(ledPin, sensorValue >> 2); +        delay(200);            // delay 200 milliseconds +      }  .. Déclencher le capteur sur demande  .. --------------------------------- diff --git a/resources/admonitions.tex b/resources/admonitions.tex index 5ab78ca..b57437f 100644 --- a/resources/admonitions.tex +++ b/resources/admonitions.tex @@ -17,7 +17,7 @@  \let\oldttfamily\ttfamily -\newenvironment{DUCLASScode}{% +\newenvironment{DUCLASSprogram}{%    \begin{mdframed}[topline=false,%      bottomline=false,%      rightline=false,% diff --git a/resources/figures.tex b/resources/figures.tex index 57e4587..a574a1f 100644 --- a/resources/figures.tex +++ b/resources/figures.tex @@ -26,3 +26,14 @@  %  \end{mdframed}%    \end{legacyFigure}%  } + +% Float environment for programs + +\floatstyle{ruled} +\newfloat{fprogram}{htbp}{lop} +\floatname{fprogram}{Programme} + +\newcommand\DUadmonitionfloatprogram[1]{\begin{fprogram}#1\end{fprogram}} +\newcommand\DUtitlefloatprogram[1]{\caption{#1}} + + | 
