Page 1 sur 2

Programme presque fini :) mais encore un probleme :/

Posté : lun. 25 mai 2015 16:23
par stratosphere
Bonjour je suis encore sur mon programme avec des led ^^ cette fois il me manque presque rien pour le faire marché voici mon programme

Code : Tout sélectionner


#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
# Une LED branchée à la pin 25 clignote
 
import RPi.GPIO as GPIO  # bibliothèque pour utiliser les GPIO
import time              # bibliothèque pour gestion du temps
 
# a adapter a ta configuration
ledverte = 25
ledrouge = 22
btvert = 23
btrouge = 24


GPIO.setmode(GPIO.BCM)   # mode de numérotation des pins
GPIO.setup(ledverte,GPIO.OUT)
GPIO.setup(ledrouge,GPIO.OUT)  
GPIO.setup(btvert,GPIO.IN)  
GPIO.setup(btrouge,GPIO.IN) 


 while True:     # boucle répétée jusqu'à l'interruption du programme
      if GPIO.input(btvert) = GPIO.HIGH:
         GPIO.output(ledverte,GPIO.HIGH)
         GPIO.output(ledrouge,GPIO.LOW)
      elif GPIO.input(btrouge) = GPIO.HIGH:
         GPIO.output(ledverte,GPIO.LOW)
         GPIO.output(ledrouge,GPIO.HIGH)
      time.sleep(0.1) # petite pause pour eviter surcharge processeur

voila mon probléme quand je lance mon programme il y a la led verte qui s'allume toute seul je ne comprend pas pourquoi ^^ mais sinon le programme marche correctement ^^
merci de m'aidé :)
cordialement

Re: Programme presque fini :) mais encore un probleme :/

Posté : lun. 25 mai 2015 17:13
par ComteZera
Bonjour,

Cela fait longtemps que je n'ai pas fait de Python, mais je pense qu'il y a une erreur au niveau de ton instruction if :
= signifie affectation
== signifie comparaison

;)

Re: Programme presque fini :) mais encore un probleme :/

Posté : lun. 25 mai 2015 18:46
par stratosphere
alors = dans mon programme j'ai essayé mais sa ne marche pas alors que == marche mieux me demande pas pourquoi ^^ je sais pas :p

Re: Programme presque fini :) mais encore un probleme :/

Posté : lun. 25 mai 2015 19:10
par EVOTk
Salut,
il me semble que ceci fonctionne tres bien :

Code : Tout sélectionner

 while True:     # boucle répétée jusqu'à l'interruption du programme
      if GPIO.input(btvert):
         GPIO.output(ledverte,GPIO.HIGH)
         GPIO.output(ledrouge,GPIO.LOW)
      elif GPIO.input(btrouge):
         GPIO.output(ledverte,GPIO.LOW)
         GPIO.output(ledrouge,GPIO.HIGH)
      time.sleep(0.1) # petite pause pour eviter surcharge processeur

Re: Programme presque fini :) mais encore un probleme :/

Posté : lun. 25 mai 2015 19:17
par stratosphere
EVOTk a écrit :Salut,
il me semble que ceci fonctionne tres bien :

Code : Tout sélectionner

 while True:     # boucle répétée jusqu'à l'interruption du programme
      if GPIO.input(btvert):
         GPIO.output(ledverte,GPIO.HIGH)
         GPIO.output(ledrouge,GPIO.LOW)
      elif GPIO.input(btrouge):
         GPIO.output(ledverte,GPIO.LOW)
         GPIO.output(ledrouge,GPIO.HIGH)
      time.sleep(0.1) # petite pause pour eviter surcharge processeur
merci je viens de tester mais j'ai toujours le problème avec ma led verte qui s'allume dés que je lance mon programme

Re: Programme presque fini :) mais encore un probleme :/

Posté : lun. 25 mai 2015 20:05
par phdenaujan
Bonsoir,

Et en ajoutant un else après le elif pour informer que si aucune des conditions n'est réuni, rien ne se passe ?

Re: Programme presque fini :) mais encore un probleme :/

Posté : lun. 25 mai 2015 20:37
par stratosphere
comment tu fait le else ?
comme sa ?

Code : Tout sélectionner

else GPIO .input(btvert) == GPIO.LOW:
        GPIO.output(ledverte,GPIO.LOW)
        GPIO.output(ledrouge,GPIO.LOW)

Re: Programme presque fini :) mais encore un probleme :/

Posté : lun. 25 mai 2015 21:13
par phdenaujan
J'utilise False comme ceci :

Code : Tout sélectionner

else GPIO.input (btvert) == False :

Re: Programme presque fini :) mais encore un probleme :/

Posté : mar. 26 mai 2015 16:58
par stratosphere
ok ok merci je vais tester sa et je te dis :)

Re: Programme presque fini :) mais encore un probleme :/

Posté : mar. 26 mai 2015 19:50
par stratosphere
alors j'ai fait comme tu ma dis mais il me dis qu'il y a une sintaxe error