Exemple #1
0
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()
    led = GroveLed(pin)
    
    led.off()
Exemple #2
0
def main():

    # print disable
    sys.stdout = open(os.devnull, 'w')

    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    display = Grove4DigitDisplay(pin, pin + 1)

    # print enable
    sys.stdout = sys.__stdout__

    args = sys.argv

    message = args[2]
    colon = int(args[3])
    clear = int(args[4])

    display.show(message)
    display.set_colon(colon)

    if clear == 1:
        display.clear()
Exemple #3
0
def main():
    from grove import helper
    helper.root_check()

    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.PWM)
    pin = sh.argv2pin(" [led-count]")

    import sys
    count = 30
    if len(sys.argv) >= 3:
        count = int(sys.argv[2])

    strip = GroveWS2813RgbStrip(pin, count)

    print('Press Ctrl-C to quit.')
    try:
        while True:
            print('Color wipe animations.')
            colorWipe(strip, Color(255, 0, 0))  # Red wipe
            colorWipe(strip, Color(0, 255, 0))  # Blue wipe
            colorWipe(strip, Color(0, 0, 255))  # Green wipe
            print('Theater chase animations.')
            theaterChase(strip, Color(127, 127, 127))  # White theater chase
            theaterChase(strip, Color(127, 0, 0))  # Red theater chase
            theaterChase(strip, Color(0, 0, 127))  # Blue theater chase
            print('Rainbow animations.')
            rainbow(strip)
            rainbowCycle(strip)
            theaterChaseRainbow(strip)

    except KeyboardInterrupt:
        # clear all leds when exit
        colorWipe(strip, Color(0, 0, 0), 10)
Exemple #4
0
def main():

    args = sys.argv

    # print disable
    sys.stdout = open(os.devnull, 'w')

    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    servo = GroveServo(pin)

    # print enable
    sys.stdout = sys.__stdout__

    controlDegree = int(args[2])

    # memo: 0.12 Sec / 60 degree
    # This logic is about 1.00 sec control. 0.05 sec * 20 = 1.00 sec :)
    count = 0
    while count < 20:
        count += 1
        print(count, '/20')
        servo.setAngle(controlDegree)
        time.sleep(0.05)
    print('finish')
def main():
    from grove import helper
    helper.root_check()

    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.PWM)
    pin = sh.argv2pin()

    ledbtn = GroveKeycap(pin)

    # the default behavior of led is
    #   single click - on
    #   double click - blink
    #   long press   - off
    # remove ''' pairs below to begin your experiment
    '''
    # define a customized event handle your self
    def cust_on_event(index, event, tm):
        # obj.led could be used to operate led
        print("event with code {}, time {}".format(event, tm))

    ledbtn.on_event = cust_on_event
    '''
    while True:
        time.sleep(1)
Exemple #6
0
def get_moisture():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveMoistureSensor(0)

    print('Detecting moisture...')
    return sensor.moisture
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveRotaryAngleSensor(pin)

    while True:
        print('Rotary Value: {}'.format(sensor.value))
        time.sleep(.2)
Exemple #8
0
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveSlidePotentiometer(pin)

    while True:
        print('Slide potentiometer value: {}'.format(sensor.value))
        time.sleep(.2)
Exemple #9
0
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveLightSensor(pin)

    print('Detecting light...')
    while True:
        print('Light value: {0}'.format(sensor.light))
        time.sleep(1)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveSoundSensor(pin)

    print('Detecting sound...')
    while True:
        print('Sound value: {0}'.format(sensor.sound))
        time.sleep(.3)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = Factory.getTemper("NTC-ADC", pin)

    print('Detecting temperature...')
    while True:
        print('{} Celsius'.format(sensor.temperature))
        time.sleep(1)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    sonar = GroveUltrasonicRanger(pin)

    print('Detecting distance...')
    while True:
        print('{} cm'.format(sonar.get_distance()))
        time.sleep(1)
Exemple #13
0
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    led = GroveLed(pin)

    while True:
        led.on()
        time.sleep(1)
        led.off()
        time.sleep(1)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveLoudnessSensor(pin)

    print('Detecting loud...')
    while True:
        value = sensor.value
        if value > 10:
            print("Loud value {}, Loud Detected.".format(value))
            time.sleep(.5)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveThumbJoystick(int(pin), int(pin + 1))

    while True:
        x, y = sensor.value
        if x > 900:
            print('Joystick Pressed')
        print("X, Y = {0} {1}".format(x, y))
        time.sleep(.2)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    swicth = GroveSwitch(pin)

    while True:
        if swicth.state:
            print("HIGH")
        else:
            print("LOW")
        time.sleep(1)
Exemple #17
0
def main():

    # print disable
    sys.stdout = open(os.devnull, 'w')

    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()
    sonar = GroveUltrasonicRanger(pin)

    # print enable
    sys.stdout = sys.__stdout__

    print(sonar.get_distance())
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    display = Grove4DigitDisplay(pin, pin + 1)

    count = 0
    while True:
        t = time.strftime("%H%M", time.localtime(time.time()))
        display.show(t)
        display.set_colon(count & 1)
        count += 1
        time.sleep(1)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    pir = GrovePiezoVibrationSensor(pin)

    def callback():
        print('****ing POTHOLE!')

    pir.on_detect = callback

    while True:
        time.sleep(1)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = Factory.getTemper("NTC-ADC", pin)

    print('Detecting temperature...')
    while True:
        print('{} Celsius'.format(sensor.temperature))
        url = 'http://127.0.0.1:8000/temperature/{}?Value={}'.format(
            pin, sensor.temperature)
        urllib.request.urlopen(url)
        time.sleep(0.4)
Exemple #21
0
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    pir = GroveMiniPIRMotionSensor(pin)

    def callback():
        print('Motion detected.')

    pir.on_detect = callback

    while True:
        time.sleep(1)
Exemple #22
0
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveAirQualitySensor(pin)

    print('Detecting ...')
    while True:
        value = sensor.value
        if value > 100:
            print("{}, High Pollution.".format(value))
        else:
            print("{}, Air Quality OK.".format(value))
        time.sleep(.1)
Exemple #23
0
def main():

    # print disable
    sys.stdout = open(os.devnull, 'w')

    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveLightSensor(pin)

    # print enable
    sys.stdout = sys.__stdout__

    print(sensor.light)
Exemple #24
0
def main():

    # print disable
    sys.stdout = open(os.devnull, 'w')

    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = Factory.getTemper("NTC-ADC", pin)

    # print enable
    sys.stdout = sys.__stdout__

    print(sensor.temperature)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveWaterSensor(pin)

    print('Detecting ...')
    while True:
        value = sensor.value
        if sensor.value > 800:
            print("{}, Detected Water.".format(value))
        else:
            print("{}, Dry.".format(value))

        time.sleep(.1)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    servo = GroveServo(pin)

    while True:
        for x in range(0, 180):
            print(x, "degree")
            servo.setAngle(x)
            time.sleep(0.05)
        for x in range(180, 0, -1):
            print(x, "degree")
            servo.setAngle(x)
            time.sleep(0.05)
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = VibrationSensor(pin)

    print('Detecting vibration...')
    while True:
	vib = sensor.vibration
	if vib > 500:
		print('Pothole detected!')
		print('Vibration strength %: {0}'.format(sensor.vibration/10))
		os.system('python /root/grove.py/grove/sendemail.py')
		os.system('python /root/grove.py/grove/sendmms.py')
	        time.sleep(.5)
Exemple #28
0
def main():
    from grove.helper import SlotHelper

    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    button = GroveButton(pin)

    block_blob_service = BlockBlobService(
        account_name="lelantussa",
        account_key="Lb7K36gtXNnJWjFA1FzedR8NO0LJ3yppGQzbmoZGuR3naqY1dyx0T68s2jQnszEannN7LdgFcAJcd8MfEf0Kfw==",
    )
    container_name = "lelantus-sa-container/4918ae98-2c60-4536-aae4-a471b0bfc962"

    def on_press(t):
        print("Button is pressed")
        print("Recording video started")
        file_name = str(uuid.uuid4()) + ".avi"
        full_path = "/home/pi/media/" + file_name
        subprocess.call(
            [
                "ffmpeg",
                "-f",
                "v4l2",
                "-framerate",
                "30",
                "-s",
                "640x480",
                "-t",
                "10",
                "-i",
                "/dev/video0",
                "media/" + file_name,
            ]
        )
        print("Recording video finished")
        print("\nUploading to Blob storage as blob: " + file_name)
        block_blob_service.create_blob_from_path(container_name, file_name, full_path)

    def on_release(t):
        print("Button is released, pressed for {0} seconds".format(round(t, 6)))

    button.on_press = on_press
    button.on_release = on_release

    while True:
        time.sleep(1)
Exemple #29
0
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.ADC)
    pin = sh.argv2pin()

    sensor = GroveRoundForceSensor(int(pin))

    while True:
        fsr = sensor.value
        print('FSR Value: {}'.format(fsr), end='')
        if fsr < 10:
            print(" - No pressure")
        elif fsr < 600:
            print(" - Light squeeze")
        else:
            print(" - Big squeeze")
        time.sleep(1.0)
Exemple #30
0
def main():
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    pin = sh.argv2pin()

    relay = GroveRelay(pin)

    while True:
        try:
            relay.on()
            time.sleep(1)
            relay.off()
            time.sleep(1)
        except KeyboardInterrupt:
            relay.off()
            print("exit")
            exit(1)