예제 #1
0
from colorsys import hls_to_rgb
from IoTPy.pyuper.uper import UPER1


with UPER1() as board, \
        board.ADC("ADC0") as adcPin1, \
        board.PWM("PWM0_0") as redPin, board.PWM("PWM0_1") as greenPin, board.PWM("PWM0_2") as bluePin:

    while True:
        # average for better results
        adc_sum = 0
        for i in xrange(20):
            adc_sum += adcPin1.read()
        adc = adc_sum/20

        hue = 0.5 + (adc-0.5)*30  # convert ADC value to color
        hue = min(hue, 1.0)
        hue = max(hue, 0.0)
        rgb = hls_to_rgb(hue, 0.5, 1)

        redPin.set_duty_cycle(rgb[0]*100)
        greenPin.set_duty_cycle(rgb[1]*100)
        bluePin.set_duty_cycle(rgb[2]*100)
예제 #2
0
from time import sleep
from IoTPy.pyuper.uper import UPER1

with UPER1() as board, board.PWM(27) as redPin:

    redPin.set_frequency(1000)

    while True:
        for i in xrange(0, 100):
            redPin.set_duty_cycle(i)
            sleep(0.01)
        for i in reversed(xrange(0, 100)):
            redPin.set_duty_cycle(i)
            sleep(0.01)
예제 #3
0
from time import sleep
from IoTPy.core.gpio import GPIO
from IoTPy.pyuper.uper import UPER1


def pir_callback(event, obj):
    print event
    if event['type'] == GPIO.RISE:
        print "Movement detected"
        led.write(0)  # turn ON the led
    elif event['type'] == GPIO.FALL:
        print "No movement"
        led.write(1)  # turn OFF the led
    else:
        print "Unknown event"


with UPER1() as board, board.GPIO(27) as led, board.GPIO(18) as button:

    button.setup(GPIO.INPUT, GPIO.PULL_UP)
    button.attach_irq(GPIO.CHANGE, pir_callback, led)

    led.setup(GPIO.OUTPUT)
    led.write(1)

    while True:
        sleep(0.5)
예제 #4
0
from time import sleep
from IoTPy.pyuper.uper import UPER1
from IoTPy.things.si70xx import Si7013, Si7020

with UPER1() as board, board.I2C("I2C0") as i2c, Si7020(
        i2c, 0x40) as si7020, Si7013(i2c, 0x41) as si7013:
    while True:
        print "Si7020 T=%.1f H=%.1f" % (si7020.temperature(),
                                        si7020.humidity())
        print "Si7013 T=%.1f H=%.1f A=%i" % (
            si7013.temperature(), si7013.humidity(), si7013.analog())
        sleep(0.5)
예제 #5
0
from time import sleep
from IoTPy.core.gpio import GPIO
from IoTPy.pyuper.uper import UPER1


def button_callback(event, obj):
    obj['counter'] += 1
    print "Interrupt %i" % obj['counter']

    button_state = (event['values'] >> event['id']) & 0x1
    obj['led'].write(button_state)


with UPER1() as board, board.GPIO(27) as redPin, board.GPIO(18) as buttonPin:

    my_object = {'led': redPin, 'counter': 0}
    buttonPin.attach_irq(GPIO.CHANGE, button_callback, my_object)

    redPin.setup(GPIO.OUTPUT)
    redPin.write(1)

    while True:
        sleep(0.5)
예제 #6
0
from time import sleep
from IoTPy.pyuper.uper import UPER1
from IoTPy.things.lm75 import Lm75

with UPER1() as board, board.I2C("I2C0") as i2c, Lm75(i2c, 79) as lm75:
    while True:
        print lm75.temperature()
        sleep(0.1)
예제 #7
0
from time import sleep
from IoTPy.core.gpio import GPIO
from IoTPy.pyuper.uper import UPER1

# This is platform dependent - please configure to your application
LED_PIN_ID = 27

with UPER1() as board, board.GPIO(LED_PIN_ID) as redPin:

    redPin.setup(GPIO.OUTPUT)  # set GPIO pin to be output

    while True:
        redPin.write(
            0
        )  # Turn led ON (LED on board is common anode - therefore inverted)
        sleep(0.5)
        redPin.write(1)  # Turn led OFF
        sleep(0.5)
예제 #8
0
from time import sleep
from IoTPy.pyuper.uper import UPER1
from IoTPy.things.am2321 import AM2321

with UPER1() as board, board.I2C("I2C0") as i2c, AM2321(i2c) as sensor:
    while True:
        sensor.read()
        print "Temperature: %.1f Humidity: %.1f" % (sensor.temperature,
                                                    sensor.humidity)
        sleep(1)