issue96:arduino
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue96:arduino [2015/05/07 10:41] – créée auntiee | issue96:arduino [2015/05/15 16:08] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | So, we’ll carry on from last month and add the sonar sensor to the circuit. | + | **So, we’ll carry on from last month and add the sonar sensor to the circuit. |
Again, these are pretty cheap, but also pretty powerful, and, as we’ll see, pretty accurate too. | Again, these are pretty cheap, but also pretty powerful, and, as we’ll see, pretty accurate too. | ||
Ligne 13: | Ligne 13: | ||
Some of the echo and trigger stuff can be tricky, but with the NewPing library, things are a bit easier: https:// | Some of the echo and trigger stuff can be tricky, but with the NewPing library, things are a bit easier: https:// | ||
+ | |||
+ | #define TRIGGER_PIN | ||
+ | #define ECHO_PIN | ||
+ | #define MAX_DISTANCE 200** | ||
+ | |||
+ | Bon. Nous allons poursuivre le travail du mois dernier en ajoutant le sonar au circuit. | ||
+ | |||
+ | À nouveau, ils sont bon marché, mais assez puissants et aussi, comme nous allons le voir, plutôt précis. | ||
+ | |||
+ | Le capteur que j'ai a 5 picots. Certains n'en ont que quatre, car, même sur le mien, seulement quatre servent. Le 5 V est sur un picot, la masse sur un autre. Les deux autres sont pour l' | ||
+ | |||
+ | Avec le code vu le mois dernier (http:// | ||
+ | |||
+ | Il y a une vidéo du module en pleine action ici : https:// | ||
+ | |||
+ | Permettez-moi de passer en revue quelques lignes de code avec mes notes et mes réflexions : | ||
+ | #include < | ||
+ | |||
+ | Ce qui concerne l' | ||
+ | https:// | ||
#define TRIGGER_PIN | #define TRIGGER_PIN | ||
Ligne 18: | Ligne 38: | ||
#define MAX_DISTANCE 200 | #define MAX_DISTANCE 200 | ||
- | The three defines are pretty self-explanatory. Three and five are the Arduino pins, and the maximum distance is in centimeters. Some estimations of these units have them hitting a target over 400cm away! | + | **The three defines are pretty self-explanatory. Three and five are the Arduino pins, and the maximum distance is in centimeters. Some estimations of these units have them hitting a target over 400cm away! |
In the main loop(): | In the main loop(): | ||
Ligne 28: | Ligne 48: | ||
myGLCD.setFont(SevenSegNumFont); | myGLCD.setFont(SevenSegNumFont); | ||
- | Maybe this one caught you out last month: | + | Maybe this one caught you out last month:** |
- | myGLCD.print(String(uS)+String(" | + | Les trois define se comprennent d' |
+ | |||
+ | Dans la boucle principale, main loop() : | ||
+ | |||
+ | L' | ||
+ | int uS = sonar.ping_cm(); | ||
+ | |||
+ | Nous réglons la couleur (comme on l'a fait le mois dernier) mais ici, nous changeons de police : | ||
+ | myGLCD.setFont(SevenSegNumFont); | ||
+ | |||
+ | La ligne ci-dessous vous a peut-être causé des soucis le mois dernier : | ||
+ | |||
+ | **myGLCD.print(String(uS)+String(" | ||
This one took me a bit to figure out. When I was using: | This one took me a bit to figure out. When I was using: | ||
Ligne 40: | Ligne 72: | ||
myGLCD.print(String(uS)+String(" | myGLCD.print(String(uS)+String(" | ||
- | This prints the number in uS (but as a string) to the screen, puts a space after it, and prints it aligned left at line 24. Why a space? Well, when you run it, you’ll see that, without the space, it leaves the old number behind and you can end up going from 13 to 93. It actually means 9 but has only overwritten the 1 from the 13 leaving the three behind. It’s a bad botch, I admit, but that’s why I’m an amateur at this! | + | This prints the number in uS (but as a string) to the screen, puts a space after it, and prints it aligned left at line 24. Why a space? Well, when you run it, you’ll see that, without the space, it leaves the old number behind and you can end up going from 13 to 93. It actually means 9 but has only overwritten the 1 from the 13 leaving the three behind. It’s a bad botch, I admit, but that’s why I’m an amateur at this!** |
+ | |||
+ | myGLCD.print(String(uS)+String(" | ||
+ | |||
+ | La comprendre m'a demandé un peu de temps. Quand j' | ||
+ | |||
+ | myGLCD.print(uS, | ||
+ | |||
+ | j' | ||
+ | |||
+ | myGLCD.print(String(uS)+String(" | ||
+ | |||
+ | Ceci imprime à l' |
issue96/arduino.1430988062.txt.gz · Dernière modification : 2015/05/07 10:41 de auntiee