コード例 #1
0
def main():
    #Grove button connected to D2 on grove connector shield
    button = grove.GroveButton(2)
    # Grove light sensor connected to A2
    lightSensor = grove.GroveLight(2)
    #Instantiate a strip of 30 LEDs on SPI bus 0 connect data-D12 and Clk - D11
    ledStrip = mylib.APA102(60, 0, False)
    ledStrip.setAllLeds(61, 0, 0, 0)
    time.sleep(1)
    text = 'Hello from the Intel Edison'
    while True:
        print(button.name(), ' value is ', button.value())
        print("Light Value: " + str(lightSensor.raw_value()))
        if button.value() == 1:
            #get the time to work from home in mins
            timeInTraffic = get_time_intraffic()
            print(timeInTraffic)
            if timeInTraffic < 30:
                print("Setting all LEDs to Green- time to leave now")
                text = 'Leave now, there is no traffic, time to work  ' + str(
                    timeInTraffic) + '   minutes'
                try:
                    subprocess.check_output(['espeak', text])
                except subprocess.CalledProcessError:
                    print("Something is not working..")
                ledStrip.setAllLeds(61, 0, 255, 0)
                time.sleep(2)
            elif timeInTraffic >= 30 and timeInTraffic < 40:
                print("Setting all LEDs to orange - hmm flip a coin")
                text = 'Hmm, there is seems to be some traffic,  time to work  ' + str(
                    timeInTraffic) + '   minutes'
                try:
                    subprocess.check_output(['espeak', text])
                except subprocess.CalledProcessError:
                    print("Something is not working..")
                ledStrip.setAllLeds(61, 200, 100, 100)
                time.sleep(2)
            elif timeInTraffic >= 40:
                print("Setting all LEDs to Red - to much traffic")
                text = 'It a bad idea to leave now, there is a lot of traffic and the time to work is  ' + str(
                    timeInTraffic) + '   minutes'
                try:
                    subprocess.check_output(['espeak', text])
                except subprocess.CalledProcessError:
                    print("Something is not working..")
                ledStrip.setAllLeds(61, 255, 0, 0)
                time.sleep(2)
            else:
                print("Do nothing")
        if lightSensor.raw_value() < 150:
            print("Light value below threshold, setting all LEDS off")
            ledStrip.setAllLeds(61, 0, 0, 0)
            time.sleep(2)
        time.sleep(1)
    # Delete the button object
    del button
コード例 #2
0
ファイル: grovebutton.py プロジェクト: zzas11/upm
def main():
    # Create the button object using GPIO pin 0
    button = grove.GroveButton(0)

    # Read the input and print, waiting one second between readings
    while 1:
        print(button.name(), ' value is ', button.value())
        time.sleep(1)

    # Delete the button object
    del button
コード例 #3
0
def main():
    # Create the Grove LED object using GPIO pin 2
    led = grove.GroveLed(13)
    btn = grove.GroveButton(3)

    while 1:
        if btn.value() == 0:
            led.on()
        else:
            led.off()

    # Delete the Grove LED object
    del led
    del btn
コード例 #4
0
ファイル: pierna.py プロジェクト: tallfat/CodeLabs
#!/usr/bin/python

import paho.mqtt.client as paho
import signal
import sys
import time

from threading import Thread
from upm import pyupm_grove as grove
from upm import pyupm_biss0001 as grovemotion

luxes = grove.GroveLight(0)
motion = grovemotion.BISS0001(6)
opening = grove.GroveButton(4)
dswitch = grove.GroveRelay(2)

mqttserver = "iot.eclipse.org"
mqttport = 1883

# Sensor Luxes


def functionSensorLuxesData():
    value = luxes.value()
    print "Publish Sensor Luxes Data: We got %s!" % value
    return value


def functionSensorLuxes():
    mqttclient = paho.Client()
    mqttclient.connect(mqttserver, mqttport, 60)
コード例 #5
0
        myLcd.setColor(255, 0, 0)
        myLcd.write('unknown error' + space)


def ChangeDisplay2(_text):
    myLcd.setCursor(1, 0)
    myLcd.write(_text + space)


ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)
myLcd.setCursor(0, 0)
myDistInterrupter1 = upmRfr359f.RFR359F(2)
myDistInterrupter2 = upmRfr359f.RFR359F(3)
myAlcoholSensor = upmMq303a.MQ303A(0, 1)
button = grove.GroveButton(4)
#myReflectiveSensor1 = upmRpr220.RPR220(4)
#myReflectiveSensor2 = upmRpr220.RPR220(5)
warmed = False
space = ' ' * 16
starttime = time.time()
btnstate = False
try:
    with open(os.path.join(sys.path[0], 'stat.json')) as data_file:
        data = json.load(data_file)
except IOError:
    with open(os.path.join(sys.path[0], 'stat.json'), 'w') as data_file:
        json.dump({}, data_file)

try:
    while 1:
コード例 #6
0
#!/usr/bin/python

# http://iotdk.intel.com/docs/master/upm/classupm_1_1_grove_button.html
# http://iotdk.intel.com/docs/master/upm/classupm_1_1_grove_relay.html

import os
import time

from threading import Thread
from upm import pyupm_grove as grove

curtainup = grove.GroveRelay(2)
curtaindown = grove.GroveRelay(3)
sensorup = grove.GroveButton(8)
sensordown = grove.GroveButton(7)
commandup = grove.GroveButton(6)
commanddown = grove.GroveButton(5)
curtainstatus = 'Stopped'

def SystemStatus():

    while True:
        #os.system('clear')
        print 'Curtain     Up: ' + str(curtainup.isOn())
        print 'Curtain   Down: ' + str(curtaindown.isOn())
        print 'Sensor      Up: ' + str(sensorup.value())
        print 'Sensor    Down: ' + str(sensordown.value())
        print ''
        print 'Curtain Status: ' + curtainstatus
        time.sleep(.5)
コード例 #7
0
ファイル: displayonLCD.py プロジェクト: SHRIVP/Upcycled-Clock
#Create for the Upcycle clock project using the Intel Edison -- display stuff on the Grove RGB LCD screen
#Author : @CarmelitoA 05/28/2017
from time import sleep
from upm import pyupm_jhd1313m1 as lcd
from upm import pyupm_grove as grove
import alarms, call_IFTTT
import get_IP, sensor_values, weather_condition, traffic_condition

import datetime

sleepTime = 3
#POT connected to pin A0
knob = grove.GroveRotary(0)
button1 = grove.GroveButton(2)
button2 = grove.GroveButton(3)
# Grove RGB LCD https://github.com/intel-iot-devkit/upm/blob/master/examples/python/jhd1313m1-lcd.py
# Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS)
myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)


def showOnLCD(line1, line2, color):
    myLcd.clear()
    # Set background color
    if (color == 'blue'): myLcd.setColor(0, 0, 255)  #blue
    if (color == 'green'): myLcd.setColor(0, 255, 0)  #Green
    if (color == 'red'): myLcd.setColor(255, 0, 0)  #Red
    if (color == 'yellow'): myLcd.setColor(255, 255, 0)  #yellow
    # Zero the cursor
    myLcd.setCursor(0, 0)
    myLcd.write(line1)
    myLcd.setCursor(1, 0)