Untitled

mail@pastecode.io avatar
unknown
python
a month ago
1.7 kB
2
Indexable
Never

import event, time, cyberpi, mbuild, mbot2
import time
i = 0
cnt = 0
Colours_list = []


@event.is_press('a')
def is_btn_press():
    cyberpi.display.show_label("No Colour", 32, "center", index= 0)
    Colours_list = []
    while True:
      if (mbuild.quad_rgb_sensor.is_color("yellow","any",1)):
        cnt = 0
        Colours_list = []
        cyberpi.display.show_label("No Colours", 32, "center", index= 0)
      if (mbuild.quad_rgb_sensor.is_color("red","any",1)):
        cnt = cnt + 1
        Colours_list.append('Red')
        cyberpi.display.show_label('Red' + str(len(Colours_list)), 32, "center", index= 0)
        cyberpi.led.on(250, 0, 0, "all")
      if (mbuild.quad_rgb_sensor.is_color("green","any",1)):
        Colours_list.append('Green')
        cnt = cnt + 1
        cyberpi.display.show_label('Green ' + str(len(Colours_list)), 32, "center", index= 0)
        cyberpi.led.on(0, 250, 0, "all")
      if (mbuild.quad_rgb_sensor.is_color("blue","any",1)):
        cnt = cnt + 1
        Colours_list.append('Blue')
        cyberpi.display.show_label('Blue ' + str(len(Colours_list)), 32, "center", index= 0)
        cyberpi.led.on(0, 0, 250, "all")
      if (mbuild.quad_rgb_sensor.is_color("white","any",1)):
        cyberpi.led.show('red orange yellow green cyan')
        for i in range(cnt):
          cyberpi.display.show_label(str(i) + str('-') + str(Colours_list[i - 1]), 24, "center", index= 0)
          if Colours_list[i] == 'Red':
            mbot2.straight(20)
          if Colours_list[i] == 'Green':
            mbot2.turn(-90)
          if Colours_list[i] == 'Blue':
            mbot2.turn(90)
          time.sleep(0.5)

Leave a Comment