---
# System prepended metadata

title: Raspberry - Python led RGB et bouton / dernière commande PrestaShop

---

# Raspberry - Python led RGB et bouton / dernière commande PrestaShop
```
# Import des librairies
import RPi.GPIO as GPIO
from time import sleep
import urllib

# Assignation des pins
greenpin = 12
redpin = 32
bluepin = 33
buttonpin = 7

# Initialisation
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(buttonpin,GPIO.IN)
GPIO.setup(greenpin,GPIO.OUT)
GPIO.setup(redpin,GPIO.OUT)
GPIO.setup(bluepin,GPIO.OUT)
red = GPIO.PWM(redpin,100)
red.start(0)
blue = GPIO.PWM(bluepin,100)
blue.start(0)
green = GPIO.PWM(greenpin,100)
green.start(0)

# Initialisation Dernière commande
page=urllib.urlopen('http://195.83.128.21/~dev1905/API/last_commande.php')
firstcommande=page.read()

# Boucle
while True:

   # Récupération des valeurs
   page=urllib.urlopen('http://195.83.128.21/~dev1905/API/last_commande.php')
    lastcommande=page.read()

    # Si l'id de la dernière commande à changé = nouvelle commande
    if firstcommande != lastcommande:
        red.ChangeDutyCycle(100)
        green.ChangeDutyCycle(25)
    buttonstatut=GPIO.input(buttonpin)
    
    # Si le bouton est activé = réinitialisation
    if buttonstatut == 1:
        red.ChangeDutyCycle(0)
        green.ChangeDutyCycle(0)
        page=urllib.urlopen('http://195.83.128.21/~dev1905/API/last_commande.php')
        firstcommande=page.read()
        blue.ChangeDutyCycle(100)
    else:
        blue.ChangeDutyCycle(0)
        
    # Répéter toutes les 5s
    sleep(5)
```