0% found this document useful (0 votes)
79 views1 page

Codigo Python Control Bluetooth Robotbit Microbit

This code defines functions to control a robot using a micro:bit controller. It sets motor speeds and servo positions based on the directional pad value, and triggers other events like color changes, sounds, and servo positions. The code initializes variables and services and sets an event handler to call the control functions when the micro:bit sends directional pad values.

Uploaded by

sofia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views1 page

Codigo Python Control Bluetooth Robotbit Microbit

This code defines functions to control a robot using a micro:bit controller. It sets motor speeds and servo positions based on the directional pad value, and triggers other events like color changes, sounds, and servo positions. The code initializes variables and services and sets an event handler to call the control functions when the micro:bit sends directional pad values.

Uploaded by

sofia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

def on_mes_dpad_controller_id_microbit_evt():

global ultimoValor
if ultimoValor != control.event_value():
ultimoValor = control.event_value()
led.stop_animation()
strip.show_color(neopixel.colors(NeoPixelColors.BLACK))
robotbit.motor_run_dual(robotbit.Motors.M1A, 0, robotbit.Motors.M2B, 0)
robotbit.servo(robotbit.Servos.S1, 0)
robotbit.servo(robotbit.Servos.S2, 120)
if control.event_value() == 1:
robotbit.motor_run_dual(robotbit.Motors.M1A, 255, robotbit.Motors.M2B, 255)
elif control.event_value() == 3:
robotbit.motor_run_dual(robotbit.Motors.M1A, -255, robotbit.Motors.M2B, -
255)
elif control.event_value() == 5:
robotbit.motor_run_dual(robotbit.Motors.M1A, 255, robotbit.Motors.M2B, -
255)
elif control.event_value() == 7:
robotbit.motor_run_dual(robotbit.Motors.M1A, -255, robotbit.Motors.M2B,
255)
elif control.event_value() == 9:
strip.show_color(neopixel.colors(NeoPixelColors.VIOLET))
elif control.event_value() == 11:
music.play_tone(659, music.beat(BeatFraction.WHOLE))
elif control.event_value() == 13:
robotbit.servo(robotbit.Servos.S2, 0)
elif control.event_value() == 15:
robotbit.servo(robotbit.Servos.S1, 120)
control.on_event(EventBusSource.MES_DPAD_CONTROLLER_ID,
EventBusValue.MICROBIT_EVT_ANY,
on_mes_dpad_controller_id_microbit_evt)

# incluir libreria robotbit y bluetooth services


ultimoValor = 0
strip: neopixel.Strip = None
strip = neopixel.create(DigitalPin.P16, 4, NeoPixelMode.RGB)
ultimoValor = 0
bluetooth.start_led_service()

You might also like