loading

Step 4: Write the program

Type on the terminal:

sudo nano rgb.py

After this put the code in the terminal window.

(see the py file)

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

RED = 25

GREEN = 24

BLUE = 23

GPIO.setup(RED,GPIO.OUT)

GPIO.output(RED,0)

GPIO.setup(GREEN,GPIO.OUT)

GPIO.output(GREEN,0)

GPIO.setup(BLUE,GPIO.OUT)

GPIO.output(BLUE,0)

try:

while (True):

request = raw_input(“RGB—>”)

if (len(request) == 3):

GPIO.output(RED,int(request[0]))

GPIO.output(GREEN,int(request[1]))

GPIO.output(BLUE,int(request[2]))

except KeyboardInterrupt:

GPIO.cleanup()

Push CTRL + X button and save the rgb.py file.

For play a sound I raccommend to use Pygame (http://www.pygame.org/news.html).<br>The code is this:<br><br>import pygame<br>pygame.mixer.init()<br>pygame.mixer.music.load(&quot;myFile.wav&quot;)<br>pygame.mixer.music.play()<br>while pygame.mixer.music.get_busy() == True:<br> continue

About This Instructable

3,324views

31favorites

License:

More by masteruan:Make SMART Your Washing Machine Arduino UNO MQTT Meteo Station Microview Digital Dice 
Add instructable to: