Пример #1
0
from libsoc_zero.GPIO import Button
from time import sleep

segundos = 10

btn1 = Button('GPIO-A')
btn2 = Button('GPIO-C')

path = 'dados.txt'
arquivo = open(path, 'w')

while segundos != 0:
    sleep(1)
    if btn1.is_pressed():
        arquivo.write('O touch foi pressionado!\t')
    else:
        arquivo.write('O touch não foi pressionado!\t')

    if btn2.is_pressed():
        arquivo.write('Há luz no ambiente!\n')
    else:
        arquivo.write('Não há luz no ambiente!\n')

    segundos -= 1

arquivo.close()
Пример #2
0

client = mqtt.Client()

client.will_set(topico, no_connection_message, 0, True)

print("\nStarting subscriber...")
client.on_disconnect = on_disconnect

client.connect(ip_broker)

client.loop_start()
print("\nStarting publisher...")
btn = Button('GPIO-A')

#####################
# rotina principal  #
#####################
ledOn = 0
ledstatus = ""
while True:
    sleep(0.3)
    if btn.is_pressed():
        if ledOn == 0:
            ledOn = 1
            ledstatus = "ON"
        else:
            ledOn = 0
            ledstatus = "OFF"
        pub = client.publish("digital", ledstatus)
Пример #3
0
from libsoc_zero.GPIO import Button
from libsoc_zero.GPIO import LED
from time import sleep

sensor = Button('GPIO-A')

gpio_red = LED('GPIO-B')

gpio_red.off()
sleep(2)

while True:
    if sensor.is_pressed():
        gpio_red.on()
        sleep(0.5)
    else:
        gpio_red.off()
        sleep(0.5)

Пример #4
0
from libsoc_zero.GPIO import Button

touch = Button('GPIO-C')

while True:
    if touch.is_pressed():
        print("Button is pressed")
    else:
        print("Button is not pressed")
Пример #5
0
#!/usr/bin/python

from libsoc_zero.GPIO import Button
from time import sleep

btnA = Button("GPIO-A")
btnB = Button("GPIO-B")
btnC = Button("GPIO-C")
btnD = Button("GPIO-D")
btnE = Button("GPIO-E")


while True:
	sleep(0.25)
	if btnA.is_pressed():
		print("Button A is pressed")
	elif btnB.is_pressed():
		print("Button B is pressed")
	elif btnC.is_pressed():
		print("Button C is pressed")
	elif btnD.is_pressed():
		print("Button D is pressed")
	elif btnE.is_pressed():
		print("Button E is pressed")
	else:
		print("Button not pressed")
Пример #6
0
#coding: utf-8

from libsoc_zero.GPIO import Button
from time import sleep
import paho.mqtt.client as mqtt
#import time

# This is the Publisher

# Cria cliente mqtt
client = mqtt.Client()

# Cria o testamento para o topico "topic/9", mensagem = "Desconectando..". QOS = 1

# Conecta o cliente ao Broker fornecido em aula
client.connect("192.168.123.17",1883,60)

# Publica a mensagem "Conectado" no topico "topic/AULA", com o QOS = 0
client.publish("topic/grupo9", "Conectado", 2)

btn1 = Button('GPIO-A')

while True:
    sleep(0.25)
    if btn1.is_pressed():
        client.publish("topic/grupo9", "1")
    else:
        client.publish("topic/grupo9", "0")
Пример #7
0
from libsoc_zero.GPIO import Button  #GPIO Libraries
from libsoc_zero.GPIO import Buzzer
from time import sleep
from time import time

helpButton = Button('GPIO-A0')
cancelButton = Button('GPIO-AB')
buzzerPin = Buzzer('GPIO-D5')

helpButton.wait_for_press()
falseAlarm = False

while falseAlarm == False:
    start = time()
    while start < 3:
        buzzerPin = HIGH
    while start < 120 and falseAlarm == False:
        if cancelButton.is_pressed():
            falseAlarm = True

if falseAlarm == False:
    findLocation()  #using GPS or Wifi
    #then send to HTML
Пример #8
0
from libsoc_zero.GPIO import Button
from time import sleep

btn = Button('GPIO-G')

while True:
    sleep(0.25)
    if btn.is_pressed():
        print('Button is pressed!')
    else:
        print('Button is not pressed!')
Пример #9
0
mqttc.connect(MQTT_HOST, MQTT_PORT, MQTT_KEEPALIVE_INTERVAL)
mqttc.loop_start()

if __name__=='__main__':
    gpio_cs = gpio.GPIO(18, gpio.DIRECTION_OUTPUT)
    with gpio.request_gpios([gpio_cs]):

        a = datetime.datetime.now()
        while True:

#Terremoto
            if tilt.is_tilted():
                terremoto = "ATENÇÃO"

#Enchente
            if water_level.is_pressed():
                enchente = "ALARME"
                relay.on()
            else:
                enchente = "OK"
                relay.off()

#Tempestade
            gpio_cs.set_high()
            sleep(0.00001)
            gpio_cs.set_low()
            rx = spi.xfer(channel_select_potenciometro)
            gpio_cs.set_high()
            shake_value = (rx[1] << 8) & 0b1100000000
            shake_value = shake_value | (rx[2] & 0xff)
            if firstpass == 1: