def setcolor(self, port, color): if self._bricks: try: port = int(port) except: pass if (port in NXT_SENSOR_PORTS): port_aux = NXT_SENSOR_PORTS[port] if color == WHITE: color = Type.COLORFULL elif color == CONSTANTS['red']: color = Type.COLORRED elif color == CONSTANTS['green']: color = Type.COLORGREEN elif color == CONSTANTS['blue']: color = Type.COLORBLUE else: color = Type.COLORNONE try: Color20(self._bricks[self.active_nxt], port_aux).set_light_color(color) except: raise logoerror(ERROR_GENERIC) else: raise logoerror(ERROR_PORT_S % port) else: raise logoerror(ERROR_BRICK)
def getColor(self, port): if self._bricks: try: port = int(port) except: pass if (port in NXT_SENSOR_PORTS): try: port_aux = NXT_SENSOR_PORTS[port] sensor = Color20(self._bricks[self.active_nxt], port_aux) return colors[sensor.get_sample()] except: return ERROR else: raise logoerror(ERROR_PORT_S % port) else: raise logoerror(ERROR_BRICK)
def detectColor(self, colorPort='PORT_3', colorValue=3, operator='>', initial=False): """ Use the color sensor to see different colors (1-6) with 6 being black and 1 being white colorPort (str): The port used for the color sensor (default='PORT_3') colorValue (int): The desired value read by the color sensor [1-6, 6->black] (default=3) operator (str): The operator to perform on the color value ['<','>','=','!='] (default='>') """ color = Color20(self.nxt.brick, eval(colorPort)) if initial: return False #don't return true until actually checked sensor value else: data = color.get_sample() #integer between 1 and 6 output = operation(data,operator,colorValue) #use user input to determine 'true' value if output: print 'ColorValue is '+operator+' '+str(colorValue) return output
def getColor(self, port): if self._bricks: try: port = int(port) except: pass if (port in NXT_SENSOR_PORTS): res = ERROR try: port_aux = NXT_SENSOR_PORTS[port] sensor = Color20(self._bricks[self.active_nxt], port_aux) res = colors[sensor.get_sample()] except: pass return res else: pass else: pass
def light_reflected(port, color): c = Color20(b, SENSORS[port]) return str(c.get_reflected_light(COLOR_NUMBER[color.lower()]))
def light(port): c = Color20(b, SENSORS[port]) return str(c.get_light_color())
def led(port, color): c = Color20(b, SENSORS[port]) c.set_light_color(COLOR_NUMBER[color.lower()]) return 'OK'