IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

condition toujours fausse.


Sujet :

Python

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau membre du Club
    Homme Profil pro
    STI2D SIN
    Inscrit en
    Avril 2018
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : STI2D SIN

    Informations forums :
    Inscription : Avril 2018
    Messages : 8
    Par défaut condition toujours fausse.
    Bonjour j'aimerais obtenir de l'aide pour mon script python , mon script python ne rentre pas dans la condition while mode auto == ["1"]: pour une raison que j'ignore, merci de bien vouloir m'aider ( pour mon projet bac ) je partage ma base de donner ainsi que le point .Py si besoin.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    import time
    import grovepi
    from grovepi import *
    import MySQLdb as mdb
    import sys
    # Connect the Grove Light Sensor to analog port A1
    # SIG,NC,VCC,GND
    light_sensor = 1
    
    # Connect the LED to digital port D4 , D3
    # SIG,NC,VCC,GND
    led0 = 4
    led1 = 3
    led2 = 8
    led3 = 7
    
    # Turn on LED once sensor exceeds threshold resistance
    threshold = 10
    # Connect the Motion Sensor to digital port D3
    pir_sensor = 5
    motion=1
    # Connect the Grove Light Sensor , output , input
    grovepi.pinMode(pir_sensor,"INPUT")
    grovepi.pinMode(light_sensor,"INPUT")
    grovepi.pinMode(led0,"OUTPUT")
    grovepi.pinMode(led1,"OUTPUT")
    grovepi.pinMode(led2,"OUTPUT")
    grovepi.pinMode(led3,"OUTPUT")
    
    while True:
        try:
            sensor_value = grovepi.analogRead(light_sensor)
            print ("light_sensor"), sensor_value
            motion=grovepi.digitalRead(pir_sensor)
            print ("pir_sensor"), motion
            resistance = (float)(1024 - sensor_value) * 10 / sensor_value
    
            con = mdb.connect('localhost','phpmyadmin','raspberry','eclairage')
            
            cur = con.cursor()
            
            
            with con:
                sensor_value = str(sensor_value)
                args = [sensor_value]
                sql = 'UPDATE eclairage SET capteurlumiere = %s WHERE id = 1'
                in_q = ', '.join(list(map(lambda x: '%s', args)))
                cur.execute(sql, args)
                con.commit()
    ## update data base capteur mouvement ////////////////////////////////
                
            with con:
                pir_motion = str(motion)
                args = [motion]
                sql = 'UPDATE eclairage SET capteurmouvement = %s WHERE id = 1' 
                in_q = ', '.join(list(map(lambda x: '%s', args)))
                cur.execute(sql, args)
                con.commit()
    ## condition ///////////////////////////////////////////////////
            with con:
                cur = con.cursor(mdb.cursors.DictCursor)
                response = cur.execute("SELECT Mode FROM eclairage WHERE id=1")
                response = cur.fetchone()
                modeauto = dict.values(response)
                print ("#############")
                time.sleep(0.4)
                
                
            while modeauto == ["1"]:
                  print ("lecture du mode auto...")
                  if motion==0 or motion==1:
                            if motion==1:
                                if resistance > threshold:
                                    grovepi.digitalWrite(led0,1)
                                    grovepi.digitalWrite(led1,1)
                                    grovepi.digitalWrite(led2,1)
                                    grovepi.digitalWrite(led3,1)
                                    time.sleep(3)
                                    print ('piscine light on')
                                    if motion==0:
                                        grovepi.digitalWrite(led0,0)
                                        grovepi.digitalWrite(led1,0)
                                        grovepi.digitalWrite(led2,0)
                                        grovepi.digitalWrite(led3,0)
                            else:
                                print ("lecture du mode manuel")
                                cur = con.cursor(mdb.cursors.DictCursor)
                                response = cur.execute("SELECT etat FROM Mode WHERE id=1")
                                response = cur.fetchone()
                                modemanuel = dict.values(response)
                                if modemanuel == ["0"]:
                                    print ('piscine mode manuel off')
                                    grovepi.digitalWrite(led0,0)
                                    grovepi.digitalWrite(led1,0)
                                    grovepi.digitalWrite(led2,0)
                                    grovepi.digitalWrite(led3,0)
                                    time.sleep(0.2)
                                    print ('piscine mode auto on')
                                    if modemanuel == ["1"]:
                                        print ('piscine mode auto on')
                                        grovepi.digitalWrite(led0,1)
                                        grovepi.digitalWrite(led1,1)
                                        grovepi.digitalWrite(led2,1)
                                        grovepi.digitalWrite(led3,1)
        except IOError:
            grovepi.digitalWrite(led0,0)
            grovepi.digitalWrite(led1,0)
            grovepi.digitalWrite(led2,0)
            grovepi.digitalWrite(led3,0)
            print ("Error")
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. Demande d'aide pour extraire des données Excel à l'aide python
    Par userinfo dans le forum Général Python
    Réponses: 5
    Dernier message: 05/01/2013, 11h45
  2. demande d'aide en python
    Par exative dans le forum Général Python
    Réponses: 10
    Dernier message: 01/12/2012, 18h06
  3. demande d'aide sur python
    Par dekiss dans le forum Général Python
    Réponses: 2
    Dernier message: 01/03/2012, 16h05
  4. Demande d'aide pour comprendre des syntaxes Python
    Par Cyberstein dans le forum Général Python
    Réponses: 13
    Dernier message: 31/12/2009, 22h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo