WeAllCode / tinybit-python

1 stars 0 forks source link

Allow user to interact with micro:bit buttons #7

Closed karbassi closed 7 months ago

blainerothrock commented 10 months ago

@karbassi any ideas on what we would want to do with the buttons?

karbassi commented 10 months ago

I'd like to be able to do something when they are pressed.

For example: press the A button and a function I wrote will run (turn the LEDs turn a random color).

blainerothrock commented 10 months ago

Ok, I have thought about this and I think I have a nice solution which will be nice to build on as we continue with the project

example code

from weallcode_robot import Robot

# Create a robot
name = "beep"
robot = Robot(name)

# assign buzz to button a press
robot.button_a.buzz(440, 0.25)

# assign led to button b press
robot.button_b.led(0, 0, 255)

# when running, the robot will execute any commands, when wait until the window is closed. If the button is pressed the commands associated with that button will be executed. 
robot.run()

as a next iteration, I think i would be neat to build in the ability to add buttons to the window which the students can program. So the students could, for example, drive the robots.

from weallcode_robot import Robot

# Create a robot
name = "beep"
robot = Robot(name)

# create a new button which will appear on the window
left_button = robot.new_button("left")

# assign a command to the left button
left_button.wheels(0,100)

robot.run()

lastly the window will be helpful for any errors, or any other helpful information.

@karbassi let me know what you think, I plan to have this done early next week.

blainerothrock commented 10 months ago

we could also assign commands to keys (e.g., drive with WASD or arrows).