Example #1
0
class presence_sensor(object):
    def __init__(self, pin):
        self.gpio = GPIO(debug=False)
        self.pin = pin
        self.gpio.pinMode(pin, self.gpio.INPUT)

    def get_value(self):
        return bool(self.gpio.digitalRead(self.pin))
Example #2
0
class Device(object):
    def __init__(self, pin_):
        self.gpio = GPIO(debug=False)
        self.gpio.pinMode(pin_, self.gpio.OUTPUT)

    def onDevice(self, pin_):
        return self.gpio.digitalWrite(pin_, self.gpio.HIGH)

    def offDevice(self, pin_):
        return self.gpio.digitalWrite(pin_, self.gpio.LOW)

    def getDevice(self, pin_):
        return self.gpio.digitalRead(pin_)
Example #3
0
pin = 13
button = 2

print 'Setting up pins %d and %d...' % (pin, button)

# Set pin 13 to be used as an output GPIO pin.
gpio.pinMode(pin, gpio.OUTPUT)

# Set pin 2 to be used as an input GPIO pin.
gpio.pinMode(button, gpio.INPUT)

print 'Reading from pin %d now...' % button
try:
    while(True):
        # Read the state of the button
        state = gpio.digitalRead(button)

        # If the button is pressed turn ON pin 13
        if state == 1:
            gpio.digitalWrite(pin, gpio.HIGH)

        # If the button is not pressed turn OFF pin 13
        else:
            gpio.digitalWrite(pin, gpio.LOW)

# Kill the loop with Ctrl-C.
except KeyboardInterrupt:
    # Leave the led turned off.
    print '\nCleaning up...'
    gpio.digitalWrite(pin, gpio.LOW)
Example #4
0
import time

gpio = GPIO(debug=False)

led = 13
dht11 = 8

print("Setting up Pins")

gpio.pinMode(dht11, gpio.INPUT)
gpio.pinMode(led, gpio.OUTPUT)

data = []

for i in range(0, 500):
    data.append(gpio.digitalRead(dht11))

bit_count = 0
tmp = 0
count = 0
hum_bit = ""
temp_bit = ""
crc = ""
try:
    while data[count] == 1:
        tmp = 1
        count += 1
    for i in range(0, 32):
        bit_count = 0

        while data[count] == 0:
Example #5
0
    time.sleep(0.2)
    print("Turning Alarm Pin On")
    gpio.digitalWrite(alarm_pin, gpio.HIGH)
    time.sleep(0.2)
    print("Turning User Pin Off")
    gpio.digitalWrite(user_pin, gpio.LOW)
    time.sleep(0.2)
    print("Turning Internet Pin Off")
    gpio.digitalWrite(internet_pin, gpio.LOW)
    time.sleep(0.2)
    print("Turning Mote Pin Off")
    gpio.digitalWrite(mote_pin, gpio.LOW)
    time.sleep(0.2)
    print("Turning Alarm Pin Off")
    gpio.digitalWrite(alarm_pin, gpio.LOW)
    time.sleep(0.2)

    print("Playing a little tune")
    for i in xrange(1000):
        gpio.digitalWrite(speaker_pin, gpio.HIGH)
        time.sleep(0.001)
        gpio.digitalWrite(speaker_pin, gpio.LOW)
        time.sleep(0.001)

    print("There is a User in the room: ",
          bool(gpio.digitalRead(presence_pin)))
    print("The Current Temperature is: ",
          (gpio.analogRead(lm35_pin) / 1024.0) * 500)
    print("The Current Luminosity is: ",
          100 - (gpio.analogRead(photo_pin) * 100 / 1024.0))
Example #6
0
import time
import subprocess

from wiringx86 import GPIOGalileoGen2 as GPIO

gpio = GPIO(debug=False)
presence_sensor = 4

gpio.pinMode(presence_sensor, gpio.INPUT)

print("Reading Now")
try:
    while (True):
        time.sleep(1)
        state = gpio.digitalRead(presence_sensor)
        print(state)

except KeyboardInterrupt:
    print("\n\nCleaning Up...")
    gpio.cleanup()