def main():
    # Instantiate the strip of 60 LEDs on SPI bus 0 connect Data-D11 and Clk- D13
    ledStrip = mylib.APA102(60, 0, False)
    knob = grove.GroveRotary(0)
    abs = knob.abs_value()
    while True:
        # Read values
        abs = knob.abs_value()
        print("Abs values: " + str(abs))
        lightValue = lightSensor.raw_value()
        print("Light Value: " + str(lightValue))
        sleep(1)
        if abs < 100:
            print("Setting all LEDs to Green")
            ledStrip.setAllLeds(60, 0, 255, 0)
            time.sleep(2)
        elif abs > 100 and abs < 300:
            print("Setting all LEDs to Red")
            ledStrip.setAllLeds(60, 255, 0, 0)
            time.sleep(2)
        elif abs > 300 and abs < 600:
            print("Setting all LEDs to Blue")
            ledStrip.setAllLeds(60, 0, 0, 255)

        elif abs > 600 and abs < 900:
            print("Setting LEDs between 10 and 20 to Red")
            ledStrip.setLeds(10, 20, 60, 255, 0, 0)
            time.sleep(2)
        else:
            print("setting all LEDS off")
            ledStrip.setAllLeds(60, 0, 0, 0)
            time.sleep(2)
Exemplo n.º 2
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
Exemplo n.º 3
0
def main():
    # Instantiate a strip of 30 LEDs on SPI bus 0
    ledStrip = mylib.APA102(30, 0, False)

    ## Exit handlers ##
    # This stops python from printing a stacktrace when you hit control-C
    def SIGINTHandler(signum, frame):
        raise SystemExit

    # Register exit handlers
    signal.signal(signal.SIGINT, SIGINTHandler)

    print("Setting all LEDs to Green")
    ledStrip.setAllLeds(31, 0, 255, 0)

    print("Setting LEDs between 10 and 20 to Red")
    ledStrip.setLeds(10, 20, 31, 255, 0, 0)

    print("Setting LED 15 to Blue")
    ledStrip.setLed(15, 31, 0, 0, 255)
Exemplo n.º 4
0
def main():
    #POT connected to pin A0 -using this to test the pannels indivisually
    knob = grove.GroveRotary(0)
    # Instantiate the LED strip
    ledStrip = mylib.APA102(numberOfLEDs, 0, False)
    ledStrip.setAllLeds(numberOfLEDs, 0, 0, 0)
    #ledStrip.setLeds(2, 3, 10, 255, 0, 0) #setting 2 and 3  to red of the 10 LEDs
    #ledStrip.setLed(7, 10, 255, 0, 255) #setting 7 to blue only
    #ledStrip.setLeds(4, 5, 10, 255, 255, 0) #yellow
    #ledStrip.setLeds(8, 9, 10, 0, 255, 255) #sky blue
    #ledStrip.setLeds(6, 7, 10, 255, 0, 255) #pink
    #ledStrip.setLeds(6, 7, 10, 100, 100, 100)  #white
    sleep(4)
    while True:
        # Read values
        abs = knob.abs_value()
        print("Abs values: " + str(abs))
        sleep(0.5)
        if abs < 100:
            print("Testing -- Setting all LEDs to blink white")
            ledStrip.setAllLeds(numberOfLEDs, 100, 100, 100)  #white
            sleep(2)
            ledStrip.setAllLeds(numberOfLEDs, 0, 0, 0)  #white
            sleep(2)
        elif abs >= 100 and abs < 250:
            print("Weather condition outside - lower most panel")
            outTemp, outHumidity, outCondition = weather_condition.weatherData(
            )
            print("Weather outside : " + outCondition)
            if outCondition == 'Rains':
                ledStrip.setLeds(0, 1, numberOfLEDs, 0, 0,
                                 255)  #blue for Rains
            elif outCondition == 'Sunny':
                ledStrip.setLeds(0, 1, numberOfLEDs, 255, 255, 0)  #yellow
            else:
                ledStrip.setLeds(0, 1, numberOfLEDs, 100, 100,
                                 100)  #white -Cloudy,Haze,Snow showers
            sleep(5)
        elif abs >= 250 and abs < 400:
            print("Traffic- time to work panel")
            timeToWork = traffic_condition.get_time_intraffic()
            print("Time in traffic" + str(timeToWork))
            if timeToWork <= 30:
                ledStrip.setLeds(2, 3, numberOfLEDs, 0, 255,
                                 0)  #green leave home now!!
            elif timeToWork > 30 and timeToWork > 45:
                ledStrip.setLeds(2, 3, numberOfLEDs, 0, 255,
                                 255)  #yellow-orange
            else:
                ledStrip.setLeds(2, 3, numberOfLEDs, 255, 0,
                                 0)  #>45 mins a lot of traffic
            sleep(5)
        elif abs >= 400 and abs < 550:
            print("Twitter Pannel")
            hastagCount = twitter_messages.tweet_count_today()
            print("Upcycleit hashtag count")
            if hastagCount <= 5:
                ledStrip.setLeds(4, 5, numberOfLEDs, 255, 0, 255)  #pink
            else:
                ledStrip.setLeds(4, 5, numberOfLEDs, 0, 0,
                                 255)  #more than 5 blue
            sleep(5)
        elif abs >= 550 and abs < 700:
            print("Gmail - unread emails")
            numberOfEmails = gmail_check.un_read_email()
            print("Number of unread emails : " + str(numberOfEmails))
            if numberOfEmails >= 5:
                ledStrip.setLeds(6, 7, numberOfLEDs, 255, 0, 0)  #red
            else:
                ledStrip.setLeds(6, 7, numberOfLEDs, 0, 255, 0)  #green
            sleep(5)
        elif abs >= 700 and abs < 850:
            print("Home - temperature and Gas")
            #airQualityVal = sensor_values.airQuality()
            temperature = sensor_values.temperature()
            #print  ("Temperature " + str(temperature) + " C" + "Air quality: " + str(airQualityVal))
            print("Temperature " + str(temperature))
            if temperature < 30:
                ledStrip.setLeds(8, 9, numberOfLEDs, 0, 255,
                                 0)  #green don't need to turn on the AC
            else:
                ledStrip.setLeds(8, 9, numberOfLEDs, 0, 255, 0)
            sleep(5)
        elif abs >= 850 and abs < 1000:
            print("Party mode!--need to implement rainbow cycle algo")
            ledStrip.setLeds(10, numberOfLEDs, 10, 255, 0, 0)
            sleep(0.5)
            ledStrip.setLeds(10, numberOfLEDs, 10, 0, 255, 0)
            sleep(0.5)
            ledStrip.setLeds(10, numberOfLEDs, 10, 0, 0, 255)
            sleep(0.5)
            ledStrip.setLeds(10, numberOfLEDs, 10, 255, 255, 0)  #yellow
            sleep(0.5)
            ledStrip.setLeds(10, numberOfLEDs, 10, 0, 255, 255)  #sky blue
            sleep(0.5)
            ledStrip.setLeds(10, numberOfLEDs, 10, 255, 0, 255)  #pink
            sleep(0.5)
            ledStrip.setLeds(10, 16, 10, 255, 0, 0)
            ledStrip.setLeds(17, 23, 10, 0, 255, 0)
            ledStrip.setLeds(23, numberOfLEDs, 10, 0, 0, 255)
            sleep(2)
        else:
            print("setting all LEDS off - pot all the way right")
            ledStrip.setAllLeds(numberOfLEDs, 0, 0, 0)
            sleep(2)