Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: latin-1 -*-
- '''
- Script python pour Raspberry Pi.
- Allume ou éteind une paire de LEDs en fonction
- des messages reçus par un module bluetooth HC-06
- '''
- import serial
- import RPi.GPIO as GPIO
- ser = serial.Serial('/dev/serial0', 9600)
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(22,GPIO.OUT)
- GPIO.setup(24,GPIO.OUT)
- etatLED1 = False
- etatLED2 = False
- while 1 :
- if (ser.inWaiting() > 0):
- message = ser.read()
- if (message == 'a'):
- GPIO.output(22,GPIO.HIGH)
- GPIO.output(24,GPIO.LOW)
- etatLED1 = True
- etatLED2 = False
- ser.write("LED 1 allumee, LED 2 eteinte.")
- if (message == 'b'):
- GPIO.output(22,GPIO.LOW)
- GPIO.output(24,GPIO.HIGH)
- etatLED1 = False
- etatLED2 = True
- ser.write("LED 1 eteinte, LED 2 allumee.")
- if (message == 'c'):
- GPIO.output(22,GPIO.LOW)
- GPIO.output(24,GPIO.LOW)
- etatLED1 = False
- etatLED2 = False
- ser.write("Les deux LEDs sont eteintes.")
- if (message == 'd'):
- GPIO.output(22,GPIO.HIGH)
- GPIO.output(24,GPIO.HIGH)
- etatLED1 = True
- etatLED2 = True
- ser.write("Les deux LEDs sont allumees.")
- if (message == 'e'):
- if (etatLED1 == True):
- GPIO.output(22,GPIO.LOW)
- etatLED1 = False
- else:
- GPIO.output(22,GPIO.HIGH)
- etatLED1 = True
- if (etatLED2 == True):
- GPIO.output(24,GPIO.LOW)
- etatLED2 = False
- else:
- GPIO.output(24,GPIO.HIGH)
- etatLED2 = True
- ser.write("Les deux LEDs ont change d'etat.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement