Exemple #1
0
def on_message(client, userdata, msg):
    if (msg.payload == "1"):
        print "on"
        GPIO.output(PINNR, True)
    else:
        print "off"
        GPIO.Output(PINNR, False)
def main():
    while True:
        dab_data = compare_transmission()
        
        light_level = dab_data[0]
        on_time = dab_data[1]
        off_time = dab_data[2]

        if check_light_level(light_level):
            gpio.output(7, gpio.HIGH)
            sleep(on_time)
        gpio.Output(7, gpio.LOW)
        sleep(off_time)
Exemple #3
0
reading = dht11.DHT11(pin=27)

while True:
    result = reading.read()
    dist = checkdist()
    endpoint = 'https://nowexpress.khanmuham.now.sh/user'
    if result.is_valid():
        print("DateTime : " + str(datetime.datetime.now()))
        print("temp %d C" % result.temperature)
        print("Measured Distance = %.1f cm" % dist)
        payload = {'Distance': dist, 'Temperature': result.temperature}
        req = requests.post(endpoint, json=payload)
        print(req.text)
    if result.temperature > 60:
        GPIO.Output(fan, True)
    time.sleep(1)
    if checkdist() < 200:
        print("motion detected")
        if 180 < checkdist() < 200:
            pwm.ChangeDutyCycle(10)
        elif 160 < checkdist() < 180:
            pwm.ChangeDutyCycle(20)
        elif 140 < checkdist() < 160:
            pwm.ChangeDutyCycle(30)
        elif 120 < checkdist() < 140:
            pwm.ChangeDutyCycle(40)
        elif 100 < checkdist() < 120:
            pwm.ChangeDutyCycle(60)
        elif 80 < checkdist() < 100:
            pwm.ChangeDutyCycle(70)
import RPi.GPIO as GPIO  #import the RPi.GPIO
import time.sleep  #import sleep-function to wait x seconds
GPIO.setmode(GPIO.BCM)  #configure GPIO as BCM
GPIO.setup(4, GPIO.OUT)  #Set BCM Pin 4 as Output-Pin (3.3V)

my_pwm = GPIO.PWM(4, 100)  #Setup PWM for BCM Pin 4 with 100 Hz
my_pwm.start(0)  #Start my_pwm with DutyCycle of 0 (basically off)

for i in range(0, 100):
    my_pwm.ChangeDutyCycle(i)  #Turn LED from Off to full brightness
    time.sleep(5)  #Wait 5 Seconds before dimming the LED back again
for i in range(100, 0):
    my_pwm.ChangeDutyCycle(i)  #Turn LED from ON to Off
    time.sleep(5)  #Wait 5 Seconds before exiting

GPIO.Output(
    4,
    False)  #If loop stopped, make shure, that there is no power on BCM Pin 4
GPIO.cleanup()  #Clean up after using GPIO
Exemple #5
0
import RPi.GPIO as GPIO  #import the RPi.GPIO
import time.sleep  #import sleep-function to wait x seconds
GPIO.setmode(GPIO.BCM)  #configure GPIO as BCM
GPIO.setup(4, GPIO.OUT)  #Set BCM Pin 4 as Output-Pin (3.3V)

limit = int(input("How often blink the LED? "))
seconds = int(input("How many seconds for the cycle? "))
i = 0  #Setup Counter i as 0
while i < limit:  #start loop that runs 10 times
    GPIO.Output(4, True)  #Set Output of BCM Pin 4 on High/True) -> LED ON
    time.sleep(seconds)  #Wait Seconds after turning on
    GPIO.Output(4, False)  #Set Output of BCM Pin 4 on Low/False -> LED OFF
    time.sleep(seconds)  # Wait Seconds after turning off
    i += 1  #Add 1 to the counter of the loop
GPIO.Output(
    4,
    False)  #If loop stopped, make shure, that there is no power on BCM Pin 4
GPIO.cleanup()  #Clean up after using GPIO