##################################### # Main.py # # File for running all MISSIONS # # together # # # ##################################### import bioglow_helpers as helper import bioglow_robot_settings as robot import bioglow_missions_3_4_5 as Run_1 # import here the name of files containing mission runs Run_1 for run 1, import bioglow_mission_2 as Run_2 # Run_2 for run 2, and so on.. import bioglow_mission_1 as Run_3 import bioglow_missions_11_6_7 as Run_4 import bioglow_mission_13 as Run_5 import bioglow_mission_12 as Run_6 import bioglow_missions_14_15 as Run_7 import bioglow_mission_8 as Run_8 # Function to classify color based on HSV def detect_color(h, s, v, reflected): if reflected > 4: if 1 < h < 11 and s <50: # brown return "Brown" elif 11 < h < 24 and s > 80: # orange return "Orange" elif 30 < h < 60 and v > 50: # yellow return "Yellow" elif 70 < h < 90 and s > 60: # neon green return "Lime" elif 100 < h < 160: # green - do it vertically not horizontally for accuracy return "Green" elif 195 < h < 198: # light blue return "Cyan" elif 210 < h < 225: # blue - do it vertically not horizontally for accuracy return "Blue" elif 260 < h < 350 and s > 80: # purple return "Purple" elif 350 < h and s > 50: #red return "Red" elif s < 15 and v > 70: # white return "White" else: return "Unknown" return "Unknown" async def main(): while True: pressed = robot.hub.buttons.pressed() h, s, v = await robot.color_sensor.hsv() reflected = await robot.color_sensor.reflection() color = detect_color(h, s, v, reflected) if helper.DEBUG : #print(color_sensor.color()) #print(h,s,v) #print(color) print(f"button pressed: {pressed}") #TODO: Add the solve_missions() function of the run number for each color here if color == "Green": print('Running Mission 1, Detect Green') await Run_1.solve_missions() elif color == "Red": print('Running Mission 2, Detect Red') await Run_2.solve_missions() elif color == "Yellow": print('Running Mission 3, Detect Yellow') await Run_3.solve_missions() elif color == "Blue": print('Running Mission 4, Detect Blue') await Run_4.solve_missions() elif color == "Purple": print('Running Mission 5, Detect Purple') await Run_5.solve_missions() elif color == "Orange": print('Running Mission 6, Detect Orange') await Run_6.solve_missions() elif color == "Cyan": print('Running Mission 7, Detect Cyan') await Run_7.solve_missions() elif color == "Lime": print('Running Mission 8, Detect Lime') await Run_8.solve_missions() elif color == "Brown": print('Running Mission Experimental, Detect Brown') await robot.wait(500) elif color == "White": print('Detect White') await robot.wait(500) else: print(f"Unknown color detected (Hue: {h}, Sat: {s}, Val: {v})") #pass # Show battery % for debugging if robot.Button.BLUETOOTH in pressed: # using bluetooth button here since away from color sensor # Get the battery voltage in millivolts (mV) battery_voltage_mV = robot.hub.battery.voltage() # Use the function with your voltage reading percentage = await helper.get_battery_percentage(float(battery_voltage_mV)) if helper.DEBUG: print(f"Battery voltage: {battery_voltage_mV} mV") print(f"Battery level: {percentage:.3f}%") print("FLL Robot System Ready!") await robot.hub.display.text(f"{percentage:.0f}") break elif pressed == None: continue await robot.wait(10) # Run the main function robot.run_task(main())