get paid to paste

RaspberryPi GPIO + Python

#!/usr/bin/env python
# Must be run as root - sudo python blink_cylon.py 

import RPi.GPIO as GPIO
import time

def setup( led ):
	GPIO.setup( led, GPIO.OUT );
	return;

def Liga( led, onoff, wait):
	LED = GPIO.output( led, onoff ); time.sleep(wait);
	return; 

def Padrao( padrao, wait):
	for i in range( 0, 8):
		Liga( LEDs[i] , int(padrao[i]), 0 )
	time.sleep(wait);
	return;

#Estes sao os PINs em modo BOARD
LEDs = [7, 11, 12, 13, 15, 16, 18, 22]

#Estes sao os PINs em modo BCM
#LEDs = [4, 17, 18, 27, 22, 23, 24, 25]

Delay = [0.15, 0.07]
BOTAO = 23 #not set yet ...

GPIO.cleanup();
#GPIO.setmode (GPIO.BCM );
GPIO.setmode (GPIO.BOARD );
ON = GPIO.HIGH; OFF = GPIO.LOW

for a in LEDs: setup( a )

for a in LEDs: Liga( a , ON, 0 )
time.sleep(1)
for a in LEDs: Liga( a , OFF, 0 )

#Testar padrao
Padrao( "11111111",  1)
Padrao( "00000000",  1)

while True:

	i=0;
	Padrao( "10000000",  Delay[1])
	while i<5:
		Padrao( "11000000",  Delay[1])
		Padrao( "01100000",  Delay[1])
		Padrao( "00110000",  Delay[1])
		Padrao( "00011000",  Delay[1])
		Padrao( "00001100",  Delay[1])
		Padrao( "00000110",  Delay[1])
		Padrao( "00000011",  Delay[1])
		Padrao( "10000001",  Delay[1])
		i=i+1;

	i=0;
	Padrao( "11000000",  Delay[1])
	while i<10:
		Padrao( "11000000",  Delay[1])
		Padrao( "01100000",  Delay[1])
		Padrao( "00110000",  Delay[1])
		Padrao( "00011000",  Delay[1])
		Padrao( "00001100",  Delay[1])
		Padrao( "00000110",  Delay[1])
		Padrao( "00000011",  Delay[1])
		Padrao( "00000011",  Delay[1])
		Padrao( "00000110",  Delay[1])
		Padrao( "00001100",  Delay[1])
		Padrao( "00011000",  Delay[1])
		Padrao( "00110000",  Delay[1])
		Padrao( "01100000",  Delay[1])
		Padrao( "11000000",  Delay[1])
		i=i+1;		

	i=0;
	while i<20:
		Padrao( "10000001",  Delay[1])
		Padrao( "01000010",  Delay[1])
		Padrao( "00100100",  Delay[1])
		Padrao( "00011000",  Delay[1])
		Padrao( "00100100",  Delay[1])
		Padrao( "01000010",  Delay[1])
		i=i+1;

Pasted: Mar 3, 2014, 11:04:14 pm
Views: 5