#########################################################
#
# Projeto: Minicuros - Utilizando a GPIO da Raspberry Pi
# Autor: Antonio Raian Mendes <*****@*****.**>
# Atividade: 3 - Debouncing digital
#
#########################################################

import RPi_emu.GPIO as GPIO
import time

#define uma variavel com o valor do pino usado
LED = 17
BTN = 18

GPIO.setmode(GPIO.BCM)
GPIO.setup(LED, GPIO.OUT)
GPIO.setup(BTN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)


def myReturn(pin):
    print("Evento %s = %s" % (pin, GPIO.input(pin)))
    btnValue = GPIO.input(BTN)
    GPIO.output(LED, btnValue)


print("Raspberry Pi Button\n")
GPIO.add_event_detect(BTN, GPIO.BOTH, callback=myReturn, bouncetime=400)

try:
    time.sleep(500)
def myReturn(pin):
    print("Evento %s = %s" % (pin, GPIO.input(pin)))
    btnValue = GPIO.input(BTN)
    GPIO.output(LED, btnValue)
 def __init__(self):       
     random.seed() #Random numero 
     self.__address = 0x70
     self.__smbus = GPIO.SMBus(0)     
     GPIO.add_autoreply(self.__address, 2, 5)
     GPIO.add_autoreply(self.__address, 3, 1)
 def write(self,value):
     self.__smbus.write_byte_data(self.__address, 0, value)
     GPIO.add_autoreply(self.__address, 1, random.randrange(0, 510, 1)) #Random numero pro registrador 1 
     return -1
Beispiel #5
0
#########################################################
#
# Projeto: Minicuros - Utilizando a GPIO da Raspberry Pi
# Autor: Antonio Raian Mendes <*****@*****.**>
# Atividade: 2 - Acender LED
#
#########################################################

import RPi_emu.GPIO as GPIO
import time

#define uma variavel com o valor do pino usado
LED = 17

#Seta o GPIO para o modo BCM, poderia ser o modo BOARD
GPIO.setmode(GPIO.BCM)
#Identifico o meu pino e digo q ele é de saída
GPIO.setup(LED, GPIO.OUT)

print("Raspberry Pi blink\n")
while 1:
    GPIO.output(LED, GPIO.HIGH)  #Aciona o pino
    time.sleep(1.5)  #Espera um segundo e meio
    GPIO.output(LED, GPIO.LOW)  #Desliga o pino
    time.sleep(0.5)  #espera meio segundo
def setPins(pins, bits):
    for led, bit in zip(pins, bits):
        # print('LED BIT', led, bit)
        GPIO.output(led, bit)
def cleanUp(leds, counter):
    print('Zerou')
    counter.clean()
    setPins(leds, binario(0))


if __name__ == '__main__':
    #define uma variavel com o valor dos pinos usado
    LEDS = [17, 27, 22, 10, 9, 11, 5, 6]
    BTN_START = 23
    BTN_CLEAR = 24

    clear()

    #Setando o modo de operação
    GPIO.setmode(GPIO.BCM)

    #inicializando todos os pinos dos leds
    for i in LEDS:
        GPIO.setup(i, GPIO.OUT, initial=GPIO.LOW)

    #Inicializando Botões
    GPIO.setup(BTN_START, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(BTN_CLEAR, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    #Cria a instancia de um contador iniciando em 0
    counter = Counter(0)

    #Cria os detectores de eventos para os pinos de entrada
    GPIO.add_event_detect(BTN_START,
                          GPIO.BOTH,