issue105:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue105:python [2016/02/10 09:19] – d52fr | issue105:python [2016/02/12 11:33] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 9: | Ligne 9: | ||
The red LED cathode is connected to GPIO 17 (Physical pin 11), yellow LED cathode is connected to GPIO 23 (Physical pin 16), and the green LED cathode is connected to GPIO 22 (Physical pin 15). The Anodes of all three LEDs are connected to one side of 220 Ohm resistors and the other sides are connected to a common 3.3 VDC. We don’t need the ground voltage for this particular project.** | The red LED cathode is connected to GPIO 17 (Physical pin 11), yellow LED cathode is connected to GPIO 23 (Physical pin 16), and the green LED cathode is connected to GPIO 22 (Physical pin 15). The Anodes of all three LEDs are connected to one side of 220 Ohm resistors and the other sides are connected to a common 3.3 VDC. We don’t need the ground voltage for this particular project.** | ||
- | Bienvenue | + | Heureux de vous revoir |
D' | D' | ||
- | Notez que les couleurs des câbles correspondent à leur fonction, à l' | + | Notez que les couleurs des câbles correspondent à leur fonction, à l' |
- | La cathode de la LED rouge est connecté à GPIO 17 (picot physique 11), la cathode de la LED jaune est connectée à GPIO 23 (picot physique 16) et la LED verte est reliée à GPIO 22 (picot physique 15). Les anodes des trois LED sont connectées à un bout des résistances de 22à ohms et les autres | + | La cathode de la LED rouge est connecté à GPIO 17 (picot physique 11), la cathode de la LED jaune est connectée à GPIO 23 (picot physique 16) et la cathode de la LED verte est reliée à GPIO 22 (picot physique 15). Les anodes des trois LED sont connectées à un bout des résistances de 220 ohms et les autres |
**Since I’ve driven only in the U.S. I’ve based the simulation on our traffic patterns. Long red light (10 seconds), green light is usually shorter than the red light time (8 seconds), and the yellow light is fairly short (2 seconds). These values are currently hard coded in the time.sleep() function calls. Feel free to change them as you see fit. | **Since I’ve driven only in the U.S. I’ve based the simulation on our traffic patterns. Long red light (10 seconds), green light is usually shorter than the red light time (8 seconds), and the yellow light is fairly short (2 seconds). These values are currently hard coded in the time.sleep() function calls. Feel free to change them as you see fit. | ||
Ligne 40: | Ligne 40: | ||
The first 9 lines are our standard import statements and a few comment lines. The next three lines define the BCM pin numbers for our LED pins. If you wish to use physical pin numbers, be sure to change the GPIO.setmode() line in the next routine (top right).** | The first 9 lines are our standard import statements and a few comment lines. The next three lines define the BCM pin numbers for our LED pins. If you wish to use physical pin numbers, be sure to change the GPIO.setmode() line in the next routine (top right).** | ||
+ | |||
+ | Comme je n'ai conduit qu'aux États-Unis, | ||
+ | |||
+ | Maintenant, commençons à travailler sur le code. | ||
+ | |||
+ | # | ||
+ | |||
+ | # Traffic Light Simulator | ||
+ | # Written by G. D. Walters | ||
+ | |||
+ | # | ||
+ | |||
+ | import RPi.GPIO as GPIO | ||
+ | import os | ||
+ | import time | ||
+ | import datetime | ||
+ | |||
+ | # | ||
+ | |||
+ | RedLedPin = 17 | ||
+ | YellowLedPin = 23 | ||
+ | GreenLedPin = 22 | ||
+ | |||
+ | Les 9 premières lignes sont des déclarations classiques d' | ||
**As I mentioned above, the GPIO.setmode needs to be changed from ‘GPIO.BCM’ to ‘GPIO.BOARD’ if you want to use the physical pin numbers instead of the BCM numbers in our definitions. The next three lines set the LED pins as output pins, and then turn all three LEDs off to start the program by setting the output value to HIGH. | **As I mentioned above, the GPIO.setmode needs to be changed from ‘GPIO.BCM’ to ‘GPIO.BOARD’ if you want to use the physical pin numbers instead of the BCM numbers in our definitions. The next three lines set the LED pins as output pins, and then turn all three LEDs off to start the program by setting the output value to HIGH. | ||
Ligne 66: | Ligne 90: | ||
• Set the output value of the pin back to 1 or high, | • Set the output value of the pin back to 1 or high, | ||
• Then print that the LED is now off.** | • Then print that the LED is now off.** | ||
+ | |||
+ | Comme indiqué dans l' | ||
+ | |||
+ | def LEDLoop(): | ||
+ | print "Green On..." | ||
+ | GPIO.output(GreenLedPin, | ||
+ | time.sleep(8) | ||
+ | GPIO.output(GreenLedPin, | ||
+ | print "Green Off..." | ||
+ | print " | ||
+ | GPIO.output(YellowLedPin, | ||
+ | time.sleep(2) | ||
+ | GPIO.output(YellowLedPin, | ||
+ | print " | ||
+ | print" | ||
+ | GPIO.output(RedLedPin, | ||
+ | time.sleep(10) | ||
+ | GPIO.output(RedLedPin, | ||
+ | print "Red Off..." | ||
+ | |||
+ | La routine LEDLoop est très simple : | ||
+ | • imprimer « < | ||
+ | • allumer la LED en mettant la valeur de sortie à 0 (niveau bas), | ||
+ | • puis une période d' | ||
+ | • remettre la sortie à la valeur 1 (niveau haut), | ||
+ | • puis imprimer que la LED est éteinte. | ||
**This is then duplicated for the Yellow and Red LEDs. The loop() routine simply forces the LEDLoop() routine to be called over and over until the user hits < | **This is then duplicated for the Yellow and Red LEDs. The loop() routine simply forces the LEDLoop() routine to be called over and over until the user hits < | ||
Ligne 81: | Ligne 131: | ||
Next time, we’ll have something that is a bit more challenging. Until then, happy programming.** | Next time, we’ll have something that is a bit more challenging. Until then, happy programming.** | ||
+ | Puis, ceci est copié pour les LED jaune et rouge. La routine loop() force simplement l' | ||
+ | |||
+ | def loop(): | ||
+ | while True: | ||
+ | LEDLoop() | ||
+ | |||
+ | La routine destroy() et la boucle principale sont les mêmes que le mois dernier : nous mettons toutes les sorties de LED au point haut, pour les éteindre, puis nous appelons GPIO.cleanup(). | ||
+ | |||
+ | Je ne suis pas sûr que nous puissions construire un programme plus simple pour faire ce que nous devons faire. | ||
+ | |||
+ | Si vous voulez, vous pouvez dupliquer les 3 LED et programmer une simulation de carrefour avant la prochaine fois. | ||
+ | |||
+ | La prochaine fois, nous aurons quelque chose d'un peu plus corsé. Jusque-là, bonne programmation. | ||
**ENCART APP | **ENCART APP | ||
- | The Official Full Circle App fot Ubuntu Touch | + | The Official Full Circle App for Ubuntu Touch |
Brian Douglass has created a fantastic app for Ubuntu Touch devices that will allow you to view current issues, and back issues, and to download and view them on your Ubuntu Touch phone/ | Brian Douglass has created a fantastic app for Ubuntu Touch devices that will allow you to view current issues, and back issues, and to download and view them on your Ubuntu Touch phone/ | ||
Ligne 95: | Ligne 158: | ||
https:// | https:// | ||
fullcircle.bhdouglass** | fullcircle.bhdouglass** | ||
+ | |||
+ | ENCART APP | ||
+ | |||
+ | L' | ||
+ | |||
+ | Brian Douglass a créé une appli fantastique pour les appareils Ubuntu Touch, qui vous permettra de voir les numéros actuels et les numéros plus anciens, et de les télécharger et de les lire sur votre téléphone/ | ||
+ | |||
+ | Installation | ||
+ | |||
+ | Soit vous cherchez « full circle » dans le magasin Ubuntu Touch et vous cliquez sur Installer, soit vous affichez l'URL ci-dessous sur votre appareil et vous cliquez sur Installer pour être transféré sur la page des téléchargements. | ||
+ | |||
+ | https:// |
issue105/python.1455092382.txt.gz · Dernière modification : 2016/02/10 09:19 de d52fr