def start(self): if super(CC, self).start(): self.color = datatypes.Color(self.command['color']) if self.command.has_key('operator'): self.operator = self.command['operator'] if log.m(log.LEVEL_COMMAND_CC): log.l('<'+str(self.getThreadID())+'> color=' + str(led.COLOR[0]) + ' ' + self.operator + ' ' + str(self.color)) for i in range(0, len(config.LED_PINS)): if ((i + 1) & self.color.Address) != 0: newColor = led.COLOR[i] if self.operator == '*': newColor = newColor * self.color if self.operator == '/': newColor = newColor / self.color if self.operator == '+': newColor = newColor + self.color if self.operator == '-': newColor = newColor - self.color led.setColor(newColor) else: if log.m(log.LEVEL_COMMAND_CC): log.l('<'+str(self.getThreadID())+'> color=' + str(self.color)) led.setColor(self.color) self.stop()
def fade(task, timeInSecs, endColor, startColor=None): if task is not None and task.state != constants.CMD_STATE_STARTED: raise RuntimeError("the thread, which is responsible for this fade has an invalid state: "+str(task.state)) if timeInSecs <= 0: raise ValueError("time cannot be 0 or below: "+str(timeInSecs)) startVolume = 0 ##timeInSecs = 20 if config.ENABLE_XBMC_REMOTE: startVolume = xbmcremote.getVolume() if startColor is None: startColor = datatypes.Color(led.COLOR[0].R, led.COLOR[0].G, led.COLOR[0].B) currentColor = datatypes.Color(startColor.R, startColor.G, startColor.B) startTime = time.time() secondsPassed = 0.0 lastVolume = startVolume while ((task is not None and (task.isStarted() and (task.thread is None or task.thread.isStarted()))) and secondsPassed <= timeInSecs): secondsPassed = time.time() - startTime #interpolate new color utils.interpolateColor(startColor, endColor, secondsPassed/timeInSecs, currentColor) #fade step filters for f in server.CurrentFilters: f.onFadeStep(timeInSecs, startColor, endColor, secondsPassed/timeInSecs) time.sleep(config.DELAY) #print startColor," ", endColor, " ", secondsPassed/timeInSecs led.setColor(currentColor) #fade end filters for f in server.CurrentFilters: f.onFadeEnd(timeInSecs, startColor, endColor)
def tempSensor(): newtemp.read_temp_raw() result = newtemp.read_temp() return (result) if __name__ == '__main__': pool = Pool() try: while True: result1 = pool.apply_async(tempSensor, ()) answer1 = result1.get() print(answer1) if answer1 > 24000: led.setColor(0x0000FF) #time.sleep(20) if rightSensor() == 0 and leftSensor() == 0 and 1 == GPIO.input( ObstaclePin): print "Move forward" print "Received Signal" robot.forward(70, 0.1) led.setColor(0x00FF00) no_barrier = True #print(temp.gettemp(idTemp)) GPIO.output(buzzpin, GPIO.LOW) if rightSensor() == 1 and leftSensor() == 0 and 1 == GPIO.input( ObstaclePin): print "RigthSensor, turn right" robot.right(50, 0.06) robot.left(30, 0.06)
import sys, pygame, os, game, led import screenobjects from gravsensor.adxl345 import adxl345 pygame.init() pygame.joystick.init() pygame.mouse.set_visible(0) game = game.Settings() #Initiate the LED led = led.Led() led.setColor(game.COLORS_TO_EYES[1]) # Used to manage how fast the screen updates clock = pygame.time.Clock() joysticks = [ pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count()) ] # Get count of joysticks joystick_count = pygame.joystick.get_count() print("Number of joysticks: {}".format(joystick_count)) #Setup the accelorometer accel = adxl345() #Check the joystick is plugged in and initiate it try: pygame.joystick.Joystick(0) except NameError: