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)
def main(): print(\ """ Make sure Grove-1-Wire-Thermocouple-Amplifier(MAX31850K) inserted in *** slot D{} *** """.format(pin)) from grove import helper helper.root_check() print("This program need overlay w1-gpio") from grove.helper import OverlayHelper w1_path = "/sys/devices/w1_bus_master1" oh = OverlayHelper(w1_path, "w1-gpio", "gpiopin=%d" % pin) print(oh) if not oh.is_installed(): print("install overlay {} ...".format(oh.name)) oh.install() print("Search MAX31850 devices ...") import os os.system("echo 1 > " + w1_path + "/w1_master_search") snr = Grove1WireThermoAmpMAX31850(w1_path + "/*/w1_slave") while True: print("Temperature: {:.2f} C".format(snr.read())) time.sleep(1.0)
def main(): from grove import helper helper.root_check() print("Insert Grove-Buzzer to Grove-Base-Hat slot PWM[12 13 VCC GND]") # Grove Base Hat for Raspberry Pi # PWM JST SLOT - PWM[12 13 VCC GND] pin = 12 # # Create the buzzer object using RaspberryPi GPIO12 mraa_pin = getGpioLookup("GPIO%02d" % pin) buzzer = upmBuzzer.Buzzer(mraa_pin) chords = [upmBuzzer.BUZZER_DO, upmBuzzer.BUZZER_RE, upmBuzzer.BUZZER_MI, upmBuzzer.BUZZER_FA, upmBuzzer.BUZZER_SOL, upmBuzzer.BUZZER_LA, upmBuzzer.BUZZER_SI]; # Print sensor name print(buzzer.name()) # Play sound (DO, RE, MI, etc.), pausing for 0.1 seconds between notes for chord_ind in range (0,7): # play each note for a half second print(buzzer.playSound(chords[chord_ind], 500000)) time.sleep(0.1) print("exiting application") # Delete the buzzer object del buzzer
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)
def main(): from grove import helper from grove.helper import helper helper.root_check() while True: time.sleep(1) #print("time cycle") print("exiting application") # Delete the buzzer object del buzzer del press
def main(): from grove import helper from grove.helper import helper helper.root_check() from grove.helper import SlotHelper sh = SlotHelper(SlotHelper.GPIO) butt_pin = sh.argv2pin() press = GroveLedButton(butt_pin) print "button assigned" # PWM JST SLOT - PWM[12 13 VCC GND] buzz_pin = 12 # # Create the buzzer object using RaspberryPi GPIO12 mraa_pin = getGpioLookup("GPIO%02d" % buzz_pin) buzzer = upmBuzzer.Buzzer(mraa_pin) print "buzzer assigned" # define a customized event handle your self def cust_on_event(index, event, tm): print "event with code {}, time {}".format(event, tm) press.led.brightness = press.led.MAX_BRIGHT if event & Button.EV_SINGLE_CLICK: press.led.light(True) print(buzzer.playSound(upmBuzzer.BUZZER_DO, 500000)) print "turn on LED" elif event & Button.EV_DOUBLE_CLICK: press.led.blink() print(buzzer.playSound(upmBuzzer.BUZZER_DO, 250000)) print "blink LED" elif event & Button.EV_LONG_PRESS: press.led.light(False) print(buzzer.playSound(upmBuzzer.BUZZER_SI, 500000)) print "turn off LED" press.on_event = cust_on_event i = 0 while True: print "time = {}".format(i) i += 1 time.sleep(1)
def main(): from grove import helper helper.root_check() from grove.helper import SlotHelper sh = SlotHelper(SlotHelper.PWM) pin = sh.argv2pin() ledbtn = GroveKeycap(pin) # remove ''' pairs below to begin your experiment ''' # define a customized event handle your self def cust_on_event(index, event, tm): print("event with code {}, time {}".format(event, tm)) ledbtn.on_event = cust_on_event ''' while True: time.sleep(1)