def start(): grovepi.pinMode(ledbar, "OUTPUT") grovepi.ledBar_init(ledbar, 0) grovepi.ledBar_orientation(ledbar, 1) pinMode(led, "OUTPUT") json_obj = getTankInfos(code) if json_obj != []: updateTankStatus(json_obj) data = checkLightUPnP() if data != None: if data[0] == '1': level = int(data[1]) else: json_brightness = getBrightnessLevel(json_obj) if json_brightness['time'] == "sun": level = float(json_brightness['brightness']) else: level = float(json_brightness['brightness']) setLedValue(int(level)) else: for i in range(0, 4): digitalWrite(led, 1) time.sleep(1) digitalWrite(led, 0) time.sleep(1) time.sleep(60) start(json_obj)
import time import grovepi # DI,DCKI,VCC,GND leftledbar = 6 rightledbar = 5 grovepi.ledBar_init(leftledbar, 0) grovepi.ledBar_init(rightledbar, 0) grovepi.pinMode(rightledbar, "OUTPUT") grovepi.pinMode(leftledbar, "OUTPUT") i = 0 grovepi.ledBar_orientation(rightledbar, 0) grovepi.ledBar_orientation(leftledbar, 0) # ledbar_setLed(pin,led,state) # led: which led (1-10) # state: off or on (0,1) # ledbar_setLevel(pin,level) # level: (0-10) while True: try: for i in range(3, 10): grovepi.ledBar_setLed(rightledbar, i, 1) grovepi.ledBar_setLed(leftledbar, i, 1) time.sleep(.05) for i in range(3, 10): grovepi.ledBar_setLed(rightledbar, i, 0) grovepi.ledBar_setLed(leftledbar, i, 0)
def setOrientation(self, greenToRed): grovepi.ledBar_orientation(self.__pin, greenToRed)
import grovepi # DI,DCKI,VCC,GND ledbar = 5 grovepi.ledBar_init(ledbar, 0) grovepi.pinMode(ledbar,"OUTPUT") i = 0 grovepi.ledBar_orientation(ledbar, 0) # ledbar_setLed(pin,led,state) # led: which led (1-10) # state: off or on (0,1) # ledbar_setLevel(pin,level) # level: (0-10) for i in range(3, 10): grovepi.ledBar_setLed(ledbar, i, 0)
time.sleep(.5) print "Test 7) Set state - save the state we just modified" # ledbar_setBits(ledbar, state) # state: (0-1023) a bit for each of the 10 LEDs grovepi.ledBar_setBits(ledbar, state) time.sleep(.5) print "Test 8) Swap orientation - green to red - current state is preserved" # ledbar_orientation(pin,orientation) # orientation: (0 = red to green, 1 = green to red) # when you reverse the led bar orientation, all methods know how to handle the new LED index # green to red grovepi.ledBar_orientation(ledbar, 1) time.sleep(.5) # red to green grovepi.ledBar_orientation(ledbar, 0) time.sleep(.5) # green to red grovepi.ledBar_orientation(ledbar, 1) time.sleep(.5) print "Test 9) Set level, again" # ledbar_setLevel(pin,level) # level: (0-10) # note the red LED is now at index 10 instead of 1
def setOrientation(self, orientationValue): print "set orientation ", orientationValue grovepi.ledBar_orientation(self.port, orientationValue) return
# TODO: Turnoff all lights when exit # grovepi.ledBar_setLevel(port_ledbar, 0) ########## YOUR CODE ENDS HERE ########## os._exit(0) signal.signal(signal.SIGINT, receiveSignal) ########## YOUR CODE GOES HERE ########## import grovepi port_ledbar = # FIXME: Put Ledbar to grovepi connector 5 port_ranger = # FIXME: Put Ledbar to grovepi connector 4 grovepi.ledBar_init(port_ledbar, 0) grovepi.ledBar_orientation(port_ledbar, 1) grovepi.pinMode(port_ledbar, "OUTPUT") range_max = 30 ledbar_nof_levels = 10 lvl = 0 while True: dist = grovepi.ultrasonicRead(port_ranger) if dist <= range_max : lvl = int((range_max - dist)/(range_max/ledbar_nof_levels)) else: lvl = 0 if lvl >= 0 and lvl <= ledbar_nof_levels: