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

Déploiement/Installation Python Discussion :

wordclock diy en python et Raspberry


Sujet :

Déploiement/Installation Python

  1. #21
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 091
    Par défaut
    Citation Envoyé par 7ced7 Voir le message
    Bah écoute.... ton code marche au poil...j'attend 10 minutes pour voir comment il gère le 35 (que j'ai renmplacé)
    remplacé comment ?

    en tout cas tu m'as donné envie de m'acheter un arduino et de me remettre au C.

  2. #22
    Membre averti
    Homme Profil pro
    diy
    Inscrit en
    Septembre 2020
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : diy
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Septembre 2020
    Messages : 61
    Par défaut
    remplacé comme ça :
    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
    111
    112
    113
    114
    115
    116
    117
    118
    119
    from datetime import datetime
    from time import sleep
    from neopixel import *
    import argparse
     
    # LED strip configuration:
    LED_COUNT      = 114      # Number of LED pixels.
    LED_PIN        = 18      # GPIO pin connected to the pixels (18 uses PWM!).
    #LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
    LED_FREQ_HZ    = 800000  # LED signal frequency in hertz (usually 800khz)
    LED_DMA        = 10      # DMA channel to use for generating signal (try 10)
    LED_BRIGHTNESS = 255     # Set to 0 for darkest and 255 for brightest
    LED_INVERT     = False   # True to invert the signal (when using NPN transistor level shift)
    LED_CHANNEL    = 0       # set to '1' for GPIOs 13, 19, 41, 45 or 53
     
     
     
    panel    = \
    "\
    ILNESTODEUX\
    QUATRETROIS\
    NEUFUNESEPT\
    HUITSIXCINQ\
    MIDIXMINUIT\
    ONZERHEURES\
    MOINSOLEDIX\
    ETRQUARTPMD\
    TRENTEOURXT\
    VINGT-CINQU\
    ....\
    "
     
     
    # stripLettre est la liste des LEDs en fonction de l'ordre des lettres dans panel
    # tient compte du tortillement du ruban
    stripLettre = list(range(110,0,-1))
    for i in range(0,110,22): stripLettre[i:i+11] = stripLettre[i:i+11][::-1]
    stripDot    = [111, 114, 113, 112]
    stripLettre += stripDot
     
     
    def convert(heure,minute):
        """convertit l'heure en texte, recherche chaque terme dans le panel,
        et utilise l'index des mots pour extraire dans stripLettre les numéros des leds à allumer"""
     
        heure  += minute>=35
        liaison = heure%12>1 and'HEURES'or heure%12 and'HEURE'or''
        heure   = (heure//12 and'MIDI'or'MINUIT','UNE','DEUX','TROIS','QUATRE','CINQ','SIX','SEPT','HUIT','NEUF','DIX','ONZE')[heure%12]
        dot     = ' . . . .'[:minute%5*2]
        minute  = ('','CINQ','DIX','ET QUART','VINGT','VINGT-CINQ','TRENTE','TRENTE CINQ','MOINS VINGT','MOINS LE QUART','MOINS DIX','MOINS CINQ')[minute//5]
        litt    = f'IL EST {heure}'
        if liaison: litt = litt + ' ' + liaison
        if minute : litt = litt + ' ' + minute
        litt += dot
        print(litt)
        output  = []
        index   = 0
        for mot in litt.split():
            i = panel.find(mot,index)
            output.extend(stripLettre[i:i+len(mot)])
            index = i + len(mot)
        return output
     
     
    def getHour():
     
        maintenant = datetime.now()
        heure      = maintenant.hour
        minute     = maintenant.minute
        return heure,minute
     
     
    # Define functions which animate LEDs in various ways.
    def colorWipe(strip, color, wait_ms=50):
        """Wipe color across display a pixel at a time."""
        for i in range(strip.numPixels()):
            strip.setPixelColor(i, color)
            strip.show()
            sleep(wait_ms/1000.0)
     
    #Show array
    def showArray(strip, color, array):
        array = set(array)
        for i in range(strip.numPixels()):
            strip.setPixelColor(i, color if (i+1) in array else Color(0,0,0))
        strip.show() 
     
    if __name__ == '__main__':
        # Process arguments
        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
        args = parser.parse_args()
     
        # Create NeoPixel object with appropriate configuration.
        strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
        # Intialize the library (must be called once before other functions).
        strip.begin()
     
        print ('Press Ctrl-C to quit.')
        if not args.clear:
            print('Use "-c" argument to clear LEDs on exit')
     
        # attendre si on est moins d'une seconde de la minute suivante
        while datetime.now().second == 59: continue
     
        try:
            while True:
     
                output = convert(*getHour())
                print(output)
                showArray(strip, Color(50,50,50), convert(*getHour()))
                # attendre 59 seconde, théoriquement on est toujours dans la seconde 0
                sleep(59-datetime.now().second)
     
                # attendre le passage à 0, théoriquement on est dans la seconde 59
                while datetime.now().second: continue
        except KeyboardInterrupt:
                if args.clear:
                     colorWipe(strip, Color(0,0,0), 10)
    Par contre je l'ai laissé tourné toute la nuit et il me sort encore midi à minuit :-(
    Sinon c'est au top! merci beaucoup!
    pour la suite j'aimerais utiliser mes 3 boutons (puisqu'ils sont là et que ça fera encore plus cool ;-) )
    dans l'idéal (idéalesque) :
    bouton 1 : luminosité (une boucle partant de 0 à 100% par incrémentation de 10%)
    bouton 2 : changer la couleur de l'ensemble
    bouton 3 : afficher la météo en un logo (ouais.... je sais cça risque d'être compliqué mais ça serait tellement bien!)

    A terme j'acheterai un capteur de luminosité pour adapter la luminosité sur base de celle choisie avec le bouton 1 :-)

  3. #23
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 091
    Par défaut
    Citation Envoyé par 7ced7 Voir le message
    remplacé comme ça :

    Par contre je l'ai laissé tourné toute la nuit et il me sort encore midi à minuit :-(
    Sinon c'est au top! merci beaucoup!
    pour la suite j'aimerais utiliser mes 3 boutons (puisqu'ils sont là et que ça fera encore plus cool ;-) )
    dans l'idéal (idéalesque) :
    bouton 1 : luminosité (une boucle partant de 0 à 100% par incrémentation de 10%)
    bouton 2 : changer la couleur de l'ensemble
    bouton 3 : afficher la météo en un logo (ouais.... je sais cça risque d'être compliqué mais ça serait tellement bien!)

    A terme j'acheterai un capteur de luminosité pour adapter la luminosité sur base de celle choisie avec le bouton 1 :-)
    effectivement, remplaces:
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
        heure   = (heure+(minute>=35))%24

  4. #24
    Membre averti
    Homme Profil pro
    diy
    Inscrit en
    Septembre 2020
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : diy
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Septembre 2020
    Messages : 61
    Par défaut
    Ben voila.... j'ai une horloge fonctionnelle
    !!! M E R C I !!!

    au niveau des boutons j'ai trouvé ceci : https://raspberry-lab.fr/Composants/...erry-Francais/
    Est-ce que je peux me baser là dessus pour mes boutons? c'est du python?
    aurais-je intérêt à tester sur un fichier strandtest avant?

  5. #25
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 091
    Par défaut
    Oui c'est du python, et non je pense que ce n'est pas la bonne méthode, je pense qu'il vaut mieux utiliser les interruptions. Après je ne connais pas le fonctionnement du raspberry. Faut faire des recherches.

  6. #26
    Membre averti
    Homme Profil pro
    diy
    Inscrit en
    Septembre 2020
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : diy
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Septembre 2020
    Messages : 61
    Par défaut
    Citation Envoyé par josmiley Voir le message
    Oui c'est du python, et non je pense que ce n'est pas la bonne méthode, je pense qu'il vaut mieux utiliser les interruptions. Après je ne connais pas le fonctionnement du raspberry. Faut faire des recherches.
    alors j'ai trouvé ceci :
    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
    #-------------------------------------------------------------------------------
    # Bibliothèques
    #-------------------------------------------------------------------------------
    import RPi.GPIO as GPIO                 #bibliothèque RPi.GPIO
    import time                             #bibliothèque time
    #-------------------------------------------------------------------------------
    pin = 22, 24, 17                                #broche utilisé en entrée
    #temps = 1                              #valeur attente en msec
    #temps = 10
    temps = 100
    #temps = 100
    #temps = 1000
     
    GPIO.setwarnings(False)                 #désactive le mode warning
    GPIO.setmode(GPIO.BCM)                  #utilisation des numéros de ports du
                                            #processeur
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
                                            #mise en entrée du port GPIO 22
                                            #et activation résistance soutirage
                                            #au ground
    if __name__ == '__main__':
        # Programme par défaut
        # print ("Début du programme")        #IHM
        # print ("Sortie par ctrl-c\n")       #IHM
         try:
             while True:                    #boucle infinie
                 entree = GPIO.input(22)   #lecture entrée
                 if (entree == False):       #si touche appuyée
                     print ('PIN22')     #IHM
             while True:                    #boucle infinie
                 entree = GPIO.input(24)   #lecture entrée
                 if (entree == False):       #si touche appuyée
                     print ('PIN24')     #IHM
             while True:                    #boucle infinie
                 entree = GPIO.input(17)   #lecture entrée
                 if (entree == False):       #si touche appuyée
                     print ('PIN17')     #IHM
     
                 time.sleep(temps / 1000)   #attente en msec
         except KeyboardInterrupt:          #sortie boucle par ctrl-c
             GPIO.cleanup()                 #libère toutes les ressources
             print('Fin du programme')  #IHM
    [/CODE]
    j'ai fais un fichier test.py pour pas foutre le bazar dans mon fichier wordclock.py
    initialement dans ce code il n'y avait qu'une pin (la 22). ça fonctionnait et j'ai donc essayé d'intégrer les 2 autres pin mais visiblement je m'y prend mal.
    en ce moment j'obtiens "PIN22" affiché dans putty lorsque je pousse sur le bouton de la pin 22 mais rien sur les autres et le python ne sort pas d'erreurs au lancement.
    une fois ce fichier fonctionnel je comptais intégrer ça dans wordclock.py et commencer à chipoter avec la luminosité et la couleur.
    je m'y prend mal?
    edit : je viens de tester ça :
    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
    #-------------------------------------------------------------------------------
    # Bibliothèques
    #-------------------------------------------------------------------------------
    import RPi.GPIO as GPIO                 #bibliothèque RPi.GPIO
    import time                             #bibliothèque time
    #-------------------------------------------------------------------------------
    pin = 17, 22, 24                                #broche utilisé en entrée
    #temps = 1                              #valeur attente en msec
    #temps = 10
    temps = 100
    #temps = 100
    #temps = 1000
     
    GPIO.setwarnings(False)                 #désactive le mode warning
    GPIO.setmode(GPIO.BCM)                  #utilisation des numéros de ports du
                                            #processeur
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
                                            #mise en entrée du port GPIO 22
                                            #et activation résistance soutirage
                                            #au ground
    if __name__ == '__main__':
        # Programme par défaut
        # print ("Début du programme")        #IHM
        # print ("Sortie par ctrl-c\n")       #IHM
         try:
             while True:                    #boucle infinie
                 entree = GPIO.input(17)   #lecture entrée
                 if (entree == False):       #si touche appuyée
                     print ('PIN17')     #IHM
                 entree = GPIO.input(22)   #lecture entrée
                 if (entree == False):       #si touche appuyée
                     print ('PIN22')     #IHM
                 entree = GPIO.input(24)   #lecture entrée
                 if (entree == False):       #si touche appuyée
                     print ('PIN24')     #IHM
     
                 time.sleep(temps / 1000)   #attente en msec
         except KeyboardInterrupt:          #sortie boucle par ctrl-c
             GPIO.cleanup()                 #libère toutes les ressources
             print('Fin du programme')  #IHM
    [/CODE]
    ça marche :-)
    je continue :-)

  7. #27
    Membre averti
    Homme Profil pro
    diy
    Inscrit en
    Septembre 2020
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : diy
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Septembre 2020
    Messages : 61
    Par défaut
    Voici mon code actuel et voici ce qu'il me retourne :
    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
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    from datetime import datetime
    from time import sleep
    from neopixel import *
    import argparse
    import RPi.GPIO as GPIO                 #bibliothèque RPi.GPIO
    import time                             #bibliothèque time
     
    # LED strip configuration:
    LED_COUNT      = 114      # Number of LED pixels.
    LED_PIN        = 18      # GPIO pin connected to the pixels (18 uses PWM!).
    #LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
    LED_FREQ_HZ    = 800000  # LED signal frequency in hertz (usually 800khz)
    LED_DMA        = 10      # DMA channel to use for generating signal (try 10)
    LED_BRIGHTNESS = 255     # Set to 0 for darkest and 255 for brightest
    LED_INVERT     = False   # True to invert the signal (when using NPN transistor level shift)
    LED_CHANNEL    = 0       # set to '1' for GPIOs 13, 19, 41, 45 or 53
    #-------------------------------------------------------------------------------
    pin = 17, 22, 24                                        #broche utilisé en entrée
    #temps = 1                                              #valeur attente en msec
    #temps = 10
    temps = 100
    #temps = 100
    #temps = 1000
    GPIO.setwarnings(False)                                 #désactive le mode warning
    GPIO.setmode(GPIO.BCM)                                  #utilisation des numéros de ports du
                                                            #processeur
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
                                                            #mise en entrée du port GPIO 22
                                                            #et activation résistance soutirage
                                                            #au ground
    if __name__ == '__main__':
         try:
             while True:                                    #boucle infinie
                 entreepin17 = GPIO.input(17)               #lecture entrée
                 if (entreepin17 == False):                 #si touche appuyée
                     print ('PIN17')                        #IHM
                 entreepin22 = GPIO.input(22)               #lecture entrée
                 if (entreepin22 == False):                 #si touche appuyée
                     print ('PIN22')                        #IHM
                 entreepin24 = GPIO.input(24)               #lecture entrée
                 if (entreepin24 == False):                 #si touche appuyée
                     print ('PIN24')                        #IHM
                 time.sleep(temps / 1000)                   #attente en msec
    #     except KeyboardInterrupt:                          #sortie boucle par ctrl-c
    #         GPIO.cleanup()                                 #libère toutes les ressources
    #         print('Fin du programme')                      #IHM
    #-------------------------------------------------------------------------------
     
     
     
    panel    = \
    "\
    ILNESTODEUX\
    QUATRETROIS\
    NEUFUNESEPT\
    HUITSIXCINQ\
    MIDIXMINUIT\
    ONZERHEURES\
    MOINSOLEDIX\
    ETRQUARTPMD\
    TRENTEOURXT\
    VINGT-CINQU\
    ....\
    "
     
     
    # stripLettre est la liste des LEDs en fonction de l'ordre des lettres dans panel
    # tient compte du tortillement du ruban
    stripLettre = list(range(110,0,-1))
    for i in range(0,110,22): stripLettre[i:i+11] = stripLettre[i:i+11][::-1]
    stripDot    = [111, 114, 113, 112]
    stripLettre += stripDot
     
     
    def convert(heure,minute):
        """convertit l'heure en texte, recherche chaque terme dans le panel,
        et utilise l'index des mots pour extraire dans stripLettre les numéros des leds à allumer"""
     
        heure   = (heure+(minute>=35))%24
        liaison = heure%12>1 and'HEURES'or heure%12 and'HEURE'or''
        heure   = (heure//12 and'MIDI'or'MINUIT','UNE','DEUX','TROIS','QUATRE','CINQ','SIX','SEPT','HUIT','NEUF','DIX','ONZE')[heure%12]
        dot     = ' . . . .'[:minute%5*2]
        minute  = ('','CINQ','DIX','ET QUART','VINGT','VINGT-CINQ','TRENTE','TRENTE CINQ','MOINS VINGT','MOINS LE QUART','MOINS DIX','MOINS CINQ')[minute//5]
        litt    = f'IL EST {heure}'
        if liaison: litt = litt + ' ' + liaison
        if minute : litt = litt + ' ' + minute
        litt += dot
        print(litt)
        output  = []
        index   = 0
        for mot in litt.split():
            i = panel.find(mot,index)
            output.extend(stripLettre[i:i+len(mot)])
            index = i + len(mot)
        return output
     
     
    def getHour():
     
        maintenant = datetime.now()
        heure      = maintenant.hour
        minute     = maintenant.minute
        return heure,minute
     
     
    # Define functions which animate LEDs in various ways.
    def colorWipe(strip, color, wait_ms=50):
        """Wipe color across display a pixel at a time."""
        for i in range(strip.numPixels()):
            strip.setPixelColor(i, color)
            strip.show()
            sleep(wait_ms/1000.0)
     
    #Show array
    def showArray(strip, color, array):
        array = set(array)
        for i in range(strip.numPixels()):
            strip.setPixelColor(i, color if (i+1) in array else Color(0,0,0))
        strip.show() 
     
    if __name__ == '__main__':
        # Process arguments
        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
        args = parser.parse_args()
     
        # Create NeoPixel object with appropriate configuration.
        strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
        # Intialize the library (must be called once before other functions).
        strip.begin()
     
        print ('Press Ctrl-C to quit.')
        if not args.clear:
            print('Use "-c" argument to clear LEDs on exit')
     
        # attendre si on est moins d'une seconde de la minute suivante
        while datetime.now().second == 59: continue
     
        try:
            while True:
     
                output = convert(*getHour())
                print(output)
                showArray(strip, Color(50,50,50), convert(*getHour()))
                # attendre 59 seconde, théoriquement on est toujours dans la seconde 0
                sleep(59-datetime.now().second)
     
                # attendre le passage à 0, théoriquement on est dans la seconde 59
                while datetime.now().second: continue
        except KeyboardInterrupt:
                if args.clear:
                     colorWipe(strip, Color(0,0,0), 10)
    ce que ça retourne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    pi@raspberrypi:~/piLedClock/rpi_ws281x/python $ sudo python wordclock.py
      File "wordclock.py", line 51
        panel   =  \
        ^
    IndentationError: unexpected unindent
    indentation c'est les espaces???

  8. #28
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 091
    Par défaut
    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
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    from datetime import datetime
    from time import sleep
    from neopixel import *
    import argparse
    import RPi.GPIO as GPIO                 #bibliothèque RPi.GPIO
    import time                             #bibliothèque time
     
    # LED strip configuration:
    LED_COUNT      = 114      # Number of LED pixels.
    LED_PIN        = 18      # GPIO pin connected to the pixels (18 uses PWM!).
    #LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
    LED_FREQ_HZ    = 800000  # LED signal frequency in hertz (usually 800khz)
    LED_DMA        = 10      # DMA channel to use for generating signal (try 10)
    LED_BRIGHTNESS = 255     # Set to 0 for darkest and 255 for brightest
    LED_INVERT     = False   # True to invert the signal (when using NPN transistor level shift)
    LED_CHANNEL    = 0       # set to '1' for GPIOs 13, 19, 41, 45 or 53
    #-------------------------------------------------------------------------------
    pin = 17, 22, 24                                        #broche utilisé en entrée
    #temps = 1                                              #valeur attente en msec
    #temps = 10
    temps = 100
    #temps = 100
    #temps = 1000
    GPIO.setwarnings(False)                                 #désactive le mode warning
    GPIO.setmode(GPIO.BCM)                                  #utilisation des numéros de ports du
                                                            #processeur
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
                                                            #mise en entrée du port GPIO 22
                                                            #et activation résistance soutirage
                                                            #au ground
     
     
    panel    = \
    "\
    ILNESTODEUX\
    QUATRETROIS\
    NEUFUNESEPT\
    HUITSIXCINQ\
    MIDIXMINUIT\
    ONZERHEURES\
    MOINSOLEDIX\
    ETRQUARTPMD\
    TRENTEOURXT\
    VINGT-CINQU\
    ....\
    "
     
     
    # stripLettre est la liste des LEDs en fonction de l'ordre des lettres dans panel
    # tient compte du tortillement du ruban
    stripLettre = list(range(110,0,-1))
    for i in range(0,110,22): stripLettre[i:i+11] = stripLettre[i:i+11][::-1]
    stripDot    = [111, 114, 113, 112]
    stripLettre += stripDot
     
     
    def convert(heure,minute):
        """convertit l'heure en texte, recherche chaque terme dans le panel,
        et utilise l'index des mots pour extraire dans stripLettre les numéros des leds à allumer"""
     
        heure   = (heure+(minute>=35))%24
        liaison = heure%12>1 and'HEURES'or heure%12 and'HEURE'or''
        heure   = (heure//12 and'MIDI'or'MINUIT','UNE','DEUX','TROIS','QUATRE','CINQ','SIX','SEPT','HUIT','NEUF','DIX','ONZE')[heure%12]
        dot     = ' . . . .'[:minute%5*2]
        minute  = ('','CINQ','DIX','ET QUART','VINGT','VINGT-CINQ','TRENTE','TRENTE CINQ','MOINS VINGT','MOINS LE QUART','MOINS DIX','MOINS CINQ')[minute//5]
        litt    = f'IL EST {heure}'
        if liaison: litt = litt + ' ' + liaison
        if minute : litt = litt + ' ' + minute
        litt += dot
        print(litt)
        output  = []
        index   = 0
        for mot in litt.split():
            i = panel.find(mot,index)
            output.extend(stripLettre[i:i+len(mot)])
            index = i + len(mot)
        return output
     
     
    def getHour():
     
        maintenant = datetime.now()
        heure      = maintenant.hour
        minute     = maintenant.minute
        return heure,minute
     
     
    # Define functions which animate LEDs in various ways.
    def colorWipe(strip, color, wait_ms=50):
        """Wipe color across display a pixel at a time."""
        for i in range(strip.numPixels()):
            strip.setPixelColor(i, color)
            strip.show()
            sleep(wait_ms/1000.0)
     
    #Show array
    def showArray(strip, color, array):
        array = set(array)
        for i in range(strip.numPixels()):
            strip.setPixelColor(i, color if (i+1) in array else Color(0,0,0))
        strip.show() 
     
    if __name__ == '__main__':
        # Process arguments
        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
        args = parser.parse_args()
     
        # Create NeoPixel object with appropriate configuration.
        strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
        # Intialize the library (must be called once before other functions).
        strip.begin()
     
        print ('Press Ctrl-C to quit.')
        if not args.clear:
            print('Use "-c" argument to clear LEDs on exit')
     
        # attendre si on est moins d'une seconde de la minute suivante
        while datetime.now().second == 59: continue
     
        try:
            while True:
     
                if datetime.now().second == 0:
     
                    output = convert(*getHour())
                    print(output)
                    showArray(strip, Color(50,50,50), convert(*getHour()))
     
                entreepin17 = GPIO.input(17)               
                if (entreepin17 == False):                 
                    print ('PIN17')
                    # met à jour au cas de dépassement de minute
                    showArray(strip, Color(50,50,50), convert(*getHour()))
                entreepin22 = GPIO.input(22)               
                if (entreepin22 == False):                 
                    print ('PIN22') 
                    # met à jour au cas de dépassement de minute
                    showArray(strip, Color(50,50,50), convert(*getHour()))                       
                entreepin24 = GPIO.input(24)               
                if (entreepin24 == False):                 
                    print ('PIN24') 
                    # met à jour au cas de dépassement de minute
                    showArray(strip, Color(50,50,50), convert(*getHour()))                       
                time.sleep(temps / 1000)                   
     
        except KeyboardInterrupt:
                if args.clear:
                     colorWipe(strip, Color(0,0,0), 10)

  9. #29
    Membre averti
    Homme Profil pro
    diy
    Inscrit en
    Septembre 2020
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : diy
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Septembre 2020
    Messages : 61
    Par défaut
    trop fort... il ne reste plus qu'a trouver le moyen de faire une "boucle" de luminosité et de couleur...

    bouton 1 : luminosité (une boucle partant de 0 à 100% par incrémentation de 10%)
    bouton 2 : changer la couleur de l'ensemble
    bouton 3 : afficher la météo en un logo (ouais.... je sais cça risque d'être compliqué mais ça serait tellement bien!)


    En gros je devrais (corrige moi si la méthodologie est mauvaise)
    1 : trouver le moyen de faire une boucle sur la luminosité et définir une variable LUM basée sur la valeur de celle ci.
    2 : trouver le moyen de faire une boucle sur la couleur et utiliser LUM pour ne pas avoir de couleur à 100% au changement.
    3 : me gratter la tête à propos de la météo ;-)

    ou :

    1 : faire une boucle sur la luminosité et définir la variable LUM
    2 : faire une boucle sur la couleur et définir la variable COUL
    3 : appliquer LUM au parametre BRIGHTNESS en tête de code et COUL a un paramètre en tête de code (à créer)
    4 : me gratter la tête à propos de la météo ;-)

    Désolé pour ces question de néophyte...

  10. #30
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 091
    Par défaut
    bouton1 de 0 à 100%, donc le bouton1 sert à éteindre les LEDs. Si tu es à 10% et que tu veux éteindre, il faudra appuyer 10 fois. Je dirais plutôt:
    appui long ==> 0%
    si 0%, appui bref ==> rappel
    sinon appui bref ==> +10%

    bouton2 changer la couleur de l'ensemble, le plus simple c'est d'utiliser une liste de couleurs prédéfinies. On pourrait bien sûr en appuyant longuement, entrer dans un mode de personnalisation plus fine des couleurs, le bouton1 servant à régler le niveau de rouge, le bouton2 le niveau de vert, et le bouton3 le niveau de bleu, mais franchement ça serait trop galère(c'était juste pour te mettre l'eau à la bouche).

  11. #31
    Membre averti
    Homme Profil pro
    diy
    Inscrit en
    Septembre 2020
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : diy
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Septembre 2020
    Messages : 61
    Par défaut
    Citation Envoyé par josmiley Voir le message
    bouton1 de 0 à 100%, donc le bouton1 sert à éteindre les LEDs. Si tu es à 10% et que tu veux éteindre, il faudra appuyer 10 fois. Je dirais plutôt:
    appui long ==> 0%
    si 0%, appui bref ==> rappel
    sinon appui bref ==> +10%
    ça ce serait parfait

    Citation Envoyé par josmiley Voir le message
    bouton2 changer la couleur de l'ensemble, le plus simple c'est d'utiliser une liste de couleurs prédéfinies. On pourrait bien sûr en appuyant longuement, entrer dans un mode de personnalisation plus fine des couleurs, le bouton1 servant à régler le niveau de rouge, le bouton2 le niveau de vert, et le bouton3 le niveau de bleu, mais franchement ça serait trop galère(c'était juste pour te mettre l'eau à la bouche).
    Je me doutais bien qu'il allait falloir des couleurs prédéfinies... ma question portait plus sur comment le rpi allait gerer le truc...
    ex : avec le bouton 1 je défini 70%(178,178,178), et avec le bouton2 je choisi d'afficher ça en vert... comment va t'il capter qu'il faut du coup utiliser (0,178,0)?

    Ha oui.... en ce moment j'arrive avec ton code à mettre une couleur lors d'un appuis bouton mais la couleur se reset à la minute suivante.

  12. #32
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 091
    Par défaut
    si vert vaut (0,255,0)
    70% vaut (int(0*0.7),int(255*0.7),int(0*0.7))

    donc:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    def calcul_couleur(couleur,lum)
    # ex: couleur vaut (200,50,125)
    # lum est pourcentage de luminosité, ex: pour 70% lum vaut 0.7
        R,G,B = *couleur
        return (int(R*lum),int(G*lum),int(B*lum))

    fais voir ta modif.

  13. #33
    Membre averti
    Homme Profil pro
    diy
    Inscrit en
    Septembre 2020
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : diy
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Septembre 2020
    Messages : 61
    Par défaut
    j'ai intégré ça en dessous du dernier "def" (ligne 105)
    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
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    #a lancer avec cd piLedClock/rpi_ws281x/python
    #et sudo python3 wordclock.py
    from datetime import datetime
    from time import sleep
    from neopixel import *
    import argparse
    import RPi.GPIO as GPIO                 #bibliothèque RPi.GPIO
    import time                             #bibliothèque time
     
    # LED strip configuration:
    LED_COUNT      = 114      # Number of LED pixels.
    LED_PIN        = 18      # GPIO pin connected to the pixels (18 uses PWM!).
    #LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
    LED_FREQ_HZ    = 800000  # LED signal frequency in hertz (usually 800khz)
    LED_DMA        = 10      # DMA channel to use for generating signal (try 10)
    LED_BRIGHTNESS = 255     # Set to 0 for darkest and 255 for brightest
    LED_INVERT     = False   # True to invert the signal (when using NPN transistor level shift)
    LED_CHANNEL    = 0       # set to '1' for GPIOs 13, 19, 41, 45 or 53
    #-------------------------------------------------------------------------------
    pin = 17, 22, 24                                        #broche utilisé en entrée
    #temps = 1                                              #valeur attente en msec
    #temps = 10
    temps = 100
    #temps = 100
    #temps = 1000
    GPIO.setwarnings(False)                                 #désactive le mode warning
    GPIO.setmode(GPIO.BCM)                                  #utilisation des numéros de ports du
                                                            #processeur
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
                                                            #mise en entrée du port GPIO 22
                                                            #et activation résistance soutirage
                                                            #au ground
     
     
    panel    = \
    "\
    ILNESTODEUX\
    QUATRETROIS\
    NEUFUNESEPT\
    HUITSIXCINQ\
    MIDIXMINUIT\
    ONZERHEURES\
    MOINSOLEDIX\
    ETRQUARTPMD\
    TRENTEOURXT\
    VINGT-CINQU\
    ....\
    "
     
     
    # stripLettre est la liste des LEDs en fonction de l'ordre des lettres dans panel
    # tient compte du tortillement du ruban
    stripLettre = list(range(110,0,-1))
    for i in range(0,110,22): stripLettre[i:i+11] = stripLettre[i:i+11][::-1]
    stripDot    = [111, 114, 113, 112]
    stripLettre += stripDot
     
     
    def convert(heure,minute):
        """convertit l'heure en texte, recherche chaque terme dans le panel,
        et utilise l'index des mots pour extraire dans stripLettre les numéros des leds à allumer"""
     
        heure   = (heure+(minute>=35))%24
        liaison = heure%12>1 and'HEURES'or heure%12 and'HEURE'or''
        heure   = (heure//12 and'MIDI'or'MINUIT','UNE','DEUX','TROIS','QUATRE','CINQ','SIX','SEPT','HUIT','NEUF','DIX','ONZE')[heure%12]
        dot     = ' . . . .'[:minute%5*2]
        minute  = ('','CINQ','DIX','ET QUART','VINGT','VINGT-CINQ','TRENTE','TRENTE CINQ','MOINS VINGT','MOINS LE QUART','MOINS DIX','MOINS CINQ')[minute//5]
        litt    = f'IL EST {heure}'
        if liaison: litt = litt + ' ' + liaison
        if minute : litt = litt + ' ' + minute
        litt += dot
        print(litt)
        output  = []
        index   = 0
        for mot in litt.split():
            i = panel.find(mot,index)
            output.extend(stripLettre[i:i+len(mot)])
            index = i + len(mot)
        return output
     
     
    def getHour():
     
        maintenant = datetime.now()
        heure      = maintenant.hour
        minute     = maintenant.minute
        return heure,minute
     
     
    # Define functions which animate LEDs in various ways.
    def colorWipe(strip, color, wait_ms=50):
        """Wipe color across display a pixel at a time."""
        for i in range(strip.numPixels()):
            strip.setPixelColor(i, color)
            strip.show()
            sleep(wait_ms/1000.0)
     
    #Show array
    def showArray(strip, color, array):
        array = set(array)
        for i in range(strip.numPixels()):
            strip.setPixelColor(i, color if (i+1) in array else Color(0,0,0))
        strip.show() 
     
    def calcul_couleur(couleur,lum)
    # ex: couleur vaut (200,50,125)
    # lum est pourcentage de luminosité, ex: pour 70% lum vaut 0.7
        R,G,B = *couleur
        return (int(R*lum),int(G*lum),int(B*lum))
     
     
    if __name__ == '__main__':
        # Process arguments
        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
        args = parser.parse_args()
     
        # Create NeoPixel object with appropriate configuration.
        strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
        # Intialize the library (must be called once before other functions).
        strip.begin()
     
        print ('Press Ctrl-C to quit.')
        if not args.clear:
            print('Use "-c" argument to clear LEDs on exit')
     
        # attendre si on est moins d'une seconde de la minute suivante
        while datetime.now().second == 59: continue
     
        try:
            while True:
     
                if datetime.now().second == 0:
     
                    output = convert(*getHour())
                    print(output)
                    showArray(strip, Color(255,50,50), convert(*getHour()))
     
                entreepin17 = GPIO.input(17)
                if (entreepin17 == False):
                    print ('PIN17')
                    # met à jour au cas de dépassement de minute
                    showArray(strip, Color(50,255,50), convert(*getHour()))
                entreepin22 = GPIO.input(22)
                if (entreepin22 == False):
                    print ('PIN22') 
                    # met à jour au cas de dépassement de minute
                    showArray(strip, Color(50,50,255), convert(*getHour()))
                entreepin24 = GPIO.input(24)
                if (entreepin24 == False):
                    print ('PIN24') 
                    # met à jour au cas de dépassement de minute
                    showArray(strip, Color(50,50,50), convert(*getHour()))
                time.sleep(temps / 1000)
     
        except KeyboardInterrupt:
                if args.clear:
                     colorWipe(strip, Color(0,0,0), 10)
    et ça me retourne ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    pi@raspberrypi:~/piLedClock/rpi_ws281x/python $ sudo python wordclock.py
      File "wordclock.py", line 105
        def calcul_couleur(couleur,lum)
                                      ^
    SyntaxError: invalid syntax

  14. #34
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 091
    Par défaut
    J'ai oublié les :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    def calcul_couleur(couleur,lum):

  15. #35
    Membre averti
    Homme Profil pro
    diy
    Inscrit en
    Septembre 2020
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : diy
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Septembre 2020
    Messages : 61
    Par défaut
    j'ai rajouté les : et ça me retourne ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    pi@raspberrypi:~/piLedClock/rpi_ws281x/python $ sudo python wordclock.py
      File "wordclock.py", line 108
        R,G,B = *couleur
               ^
    SyntaxError: can't use starred expression here

  16. #36
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 091
    Par défaut
    oui ma faute, faut enlever l'étoile

  17. #37
    Membre averti
    Homme Profil pro
    diy
    Inscrit en
    Septembre 2020
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : diy
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Septembre 2020
    Messages : 61
    Par défaut
    Citation Envoyé par josmiley Voir le message
    oui ma faute, faut enlever l'étoile
    c'était ma question suivante... à quoi sert l'étoile ?

    Sinon le résultat est que lorsque j'appuie sur un des boutons j'ai bien la couleur correspondante qui s'affiche, par contre à chaque minute qui passe je retourne à la couleur de base.
    Ha oui... au lancement il prend une minute pour être à l'heure maintenant

  18. #38
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 091
    Par défaut
    à tester ... mise à l'heure immédiate normalement, pin17 niveau de luminosité(pas d'extinction pour le moment), pin22 changement couleur) ... sûr de rien

    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
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    #a lancer avec cd piLedClock/rpi_ws281x/python
    #et sudo python3 wordclock.py
    from datetime import datetime
    from time import sleep
    from neopixel import *
    import argparse
    import RPi.GPIO as GPIO                 #bibliothèque RPi.GPIO
    import time                             #bibliothèque time
     
    # LED strip configuration:
    LED_COUNT      = 114      # Number of LED pixels.
    LED_PIN        = 18      # GPIO pin connected to the pixels (18 uses PWM!).
    #LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
    LED_FREQ_HZ    = 800000  # LED signal frequency in hertz (usually 800khz)
    LED_DMA        = 10      # DMA channel to use for generating signal (try 10)
    LED_BRIGHTNESS = 255     # Set to 0 for darkest and 255 for brightest
    LED_INVERT     = False   # True to invert the signal (when using NPN transistor level shift)
    LED_CHANNEL    = 0       # set to '1' for GPIOs 13, 19, 41, 45 or 53
    #-------------------------------------------------------------------------------
    pin = 17, 22, 24                                        #broche utilisé en entrée
    #temps = 1                                              #valeur attente en msec
    #temps = 10
    temps = 100
    #temps = 100
    #temps = 1000
    GPIO.setwarnings(False)                                 #désactive le mode warning
    GPIO.setmode(GPIO.BCM)                                  #utilisation des numéros de ports du
                                                            #processeur
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
                                                            #mise en entrée du port GPIO 22
                                                            #et activation résistance soutirage
                                                            #au ground
     
     
    panel    = \
    "\
    ILNESTODEUX\
    QUATRETROIS\
    NEUFUNESEPT\
    HUITSIXCINQ\
    MIDIXMINUIT\
    ONZERHEURES\
    MOINSOLEDIX\
    ETRQUARTPMD\
    TRENTEOURXT\
    VINGT-CINQU\
    ....\
    "
     
     
    # stripLettre est la liste des LEDs en fonction de l'ordre des lettres dans panel
    # tient compte du tortillement du ruban
    stripLettre = list(range(110,0,-1))
    for i in range(0,110,22): stripLettre[i:i+11] = stripLettre[i:i+11][::-1]
    stripDot    = [111, 114, 113, 112]
    stripLettre += stripDot
     
     
    def convert(heure,minute):
        """convertit l'heure en texte, recherche chaque terme dans le panel,
        et utilise l'index des mots pour extraire dans stripLettre les numéros des leds à allumer"""
     
        heure   = (heure+(minute>=35))%24
        liaison = heure%12>1 and'HEURES'or heure%12 and'HEURE'or''
        heure   = (heure//12 and'MIDI'or'MINUIT','UNE','DEUX','TROIS','QUATRE','CINQ','SIX','SEPT','HUIT','NEUF','DIX','ONZE')[heure%12]
        dot     = ' . . . .'[:minute%5*2]
        minute  = ('','CINQ','DIX','ET QUART','VINGT','VINGT-CINQ','TRENTE','TRENTE CINQ','MOINS VINGT','MOINS LE QUART','MOINS DIX','MOINS CINQ')[minute//5]
        litt    = f'IL EST {heure}'
        if liaison: litt = litt + ' ' + liaison
        if minute : litt = litt + ' ' + minute
        litt += dot
        print(litt)
        output  = []
        index   = 0
        for mot in litt.split():
            i = panel.find(mot,index)
            output.extend(stripLettre[i:i+len(mot)])
            index = i + len(mot)
        return output
     
     
    def getHour():
     
        maintenant = datetime.now()
        heure      = maintenant.hour
        minute     = maintenant.minute
        return heure,minute
     
     
    # Define functions which animate LEDs in various ways.
    def colorWipe(strip, color, wait_ms=50):
        """Wipe color across display a pixel at a time."""
        for i in range(strip.numPixels()):
            strip.setPixelColor(i, color)
            strip.show()
            sleep(wait_ms/1000.0)
     
    #Show array
    def showArray(strip, color, array):
        array = set(array)
        for i in range(strip.numPixels()):
            strip.setPixelColor(i, color if (i+1) in array else Color(0,0,0))
        strip.show() 
     
     
    def get_color():
        R,G,B = list_color[index_color]
        return (int(R*lum),int(G*lum),int(B*lum))
     
    list_color      = [(253, 51, 100), (138, 36, 177), (240, 120, 228), (129, 77, 86), (111, 147, 168), (221, 254, 42), (152, 216, 39), (166, 165, 158), (144, 44, 102), (236, 25, 252)]
    index_color     = 0
    current_bright  = 1
     
     
    if __name__ == '__main__':
        # Process arguments
        parser = argparse.ArgumentParser()
        parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
        args = parser.parse_args()
     
        # Create NeoPixel object with appropriate configuration.
        strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
        # Intialize the library (must be called once before other functions).
        strip.begin()
     
        print ('Press Ctrl-C to quit.')
        if not args.clear:
            print('Use "-c" argument to clear LEDs on exit')
     
        # attendre si on est moins d'une seconde de la minute suivante
        while datetime.now().second == 59: continue
        showArray(strip, get_color(), convert(*getHour()))
     
        try:
            while True:
     
                if datetime.now().second == 0:
     
                    output = convert(*getHour())
                    print(output)
                    showArray(strip, get_color(), convert(*getHour()))
     
                entreepin17 = GPIO.input(17)
                if (entreepin17 == False):
                    print ('PIN17')
                    current_bright = round((current_bright+.1)%1.1,1) or .1
                    # met à jour au cas de dépassement de minute
                    showArray(strip, get_color(), convert(*getHour()))
     
                entreepin22 = GPIO.input(22)
                if (entreepin22 == False):
                    print ('PIN22')
                    index_color = (index_color+1)%len(list_color)
                    # met à jour au cas de dépassement de minute
                    showArray(strip, get_color(), convert(*getHour()))
     
                entreepin24 = GPIO.input(24)
                if (entreepin24 == False):
                    print ('PIN24') 
                    # met à jour au cas de dépassement de minute
                    showArray(strip, get_color(), convert(*getHour()))
                time.sleep(temps / 1000)
     
        except KeyboardInterrupt:
                if args.clear:
                     colorWipe(strip, Color(0,0,0), 10)

  19. #39
    Membre averti
    Homme Profil pro
    diy
    Inscrit en
    Septembre 2020
    Messages
    61
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : diy
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Septembre 2020
    Messages : 61
    Par défaut
    ça retourne ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    pi@raspberrypi:~/piLedClock/rpi_ws281x/python $ sudo python wordclock.py
    Press Ctrl-C to quit.
    Use "-c" argument to clear LEDs on exit
    Traceback (most recent call last):
      File "wordclock.py", line 132, in <module>
        showArray(strip, get_color(), convert(*getHour()))
      File "wordclock.py", line 108, in get_color
        return (int(R*lum),int(G*lum),int(B*lum))

  20. #40
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 091
    Par défaut
    arf, oui ...
    remplace get_color comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    def get_color():
        R,G,B = list_color[index_color]
        return (int(R*current_bright),int(G*current_bright),int(B*current_bright))

Discussions similaires

  1. Python sur raspberry et POST
    Par joseph20480 dans le forum Général Python
    Réponses: 0
    Dernier message: 04/02/2018, 01h34
  2. Python Tweepy Raspberry
    Par pi3dany dans le forum Raspberry Pi
    Réponses: 4
    Dernier message: 14/03/2017, 19h54
  3. conseils pour serveur python sur raspberry
    Par nma dans le forum Raspberry Pi
    Réponses: 1
    Dernier message: 12/11/2016, 14h34
  4. Conenxion SSH python et raspberry
    Par Stoufiler dans le forum Réseau/Web
    Réponses: 4
    Dernier message: 14/06/2015, 18h24
  5. Python et Raspberry
    Par Horizon1956 dans le forum Raspberry Pi
    Réponses: 1
    Dernier message: 14/12/2014, 14h09

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