Example #1
0
 def read_color(self):
     white_thress = 550
     black_thress = 50
     try:
         as7262.soft_reset()
         hw_code, hw_version, fw_version = as7262.get_version()
         as7262.set_gain(2)
         as7262.set_integration_time(0.1)
         as7262.set_measurement_mode(3)
         as7262.set_illumination_led(1)
         values = as7262.get_calibrated_values()
         as7262.set_measurement_mode(3)
         as7262.set_illumination_led(0)
         string = ("{},{},{},{},{},{}").format(*values)
         colors = string.split(",")
         r = float(colors[0])
         o = float(colors[1])
         y = float(colors[2])
         g = float(colors[3])
         b = float(colors[4])
         v = float(colors[5])
         float_colors = list(map(float, colors))
         max_c = max(float_colors)
         max_s = 'RED'
         if o == max_c:
             max_c = o
             max_s = 'RED'  #'ORANGE'
         elif r == max_c:
             max_c = r
             max_s = 'RED'  #'RED'
         elif y == max_c:
             max_c = y
             max_s = 'YELLOW'
         elif g == max_c:
             max_c = g
             max_s = 'GREEN'
         elif b == max_c:
             max_c = b
             max_s = 'BLUE'
         elif v == max_c:
             max_c = v
             max_s = 'BLUE'  #'VIOLET'
         mean = statistics.mean(float_colors)
         if mean < black_thress:
             max_s = 'BLACK'
         elif mean > white_thress:
             max_s = 'WHITE'
         self.dictionary["color"] = max_s
     except:
         self.infologger.write_error("Error: I2C: reading color.")
         self.master.status_vector["INFRARED"] = 0
         self.dictionary["color"] = None
Example #2
0
BAR_CHAR = u'\u2588'

ANSI_COLOR_RED = '\x1b[31m'
ANSI_COLOR_GREEN = '\x1b[32m'
ANSI_COLOR_YELLOW = '\x1b[33m'
ANSI_COLOR_BLUE = '\x1b[34m'
ANSI_COLOR_MAGENTA = '\x1b[35m'

MAX_VALUE = 14000.0
BAR_WIDTH = 25

as7262.soft_reset()
as7262.set_gain(64)
as7262.set_integration_time(17.857)
as7262.set_measurement_mode(2)
as7262.set_illumination_led(1)

try:
    input = raw_input
except NameError:
    pass

input(
    "Setting white point baseline.\n\nHold a white sheet of paper ~5cm in front of the sensor and press a key...\n"
)
baseline = as7262.get_calibrated_values()
time.sleep(1)
input("Baseline set. Press a key to continue...\n")
sys.stdout.flush()

try:
Example #3
0
def test_illumination_led():
    """Test the illumination_led method."""
    _setup()

    as7262.set_illumination_led(1)
    assert as7262._as7262.LED_CONTROL.get_illumination_enable() == 1