ringbit remote controlled car
bouton A+B pour avancer bouton A seul pour tourner à gauche bouton B seul pour tourner à droite
This commit is contained in:
66
ringbit_car.py
Normal file
66
ringbit_car.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import microbit
|
||||||
|
import radio
|
||||||
|
|
||||||
|
# https://www.firialabs.com/blogs/lab-notes/continuous-rotation-servos-with-python-and-the-micro-bit
|
||||||
|
|
||||||
|
class MicrobitCServo:
|
||||||
|
""" Microbit continuous servo controller """
|
||||||
|
|
||||||
|
def __init__(self, pin):
|
||||||
|
self.pin = pin
|
||||||
|
|
||||||
|
def clockwise(self):
|
||||||
|
self.pin.write_analog(1023 * 1.0 / 20)
|
||||||
|
|
||||||
|
def counterclockwise(self):
|
||||||
|
self.pin.write_analog(1023 * 2.0 / 20)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
# self.pin.write_analog(0)
|
||||||
|
self.pin.write_analog(1023 * 1.5 / 20)
|
||||||
|
|
||||||
|
class RingCar:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.left_pin = microbit.pin1
|
||||||
|
self.right_pin = microbit.pin2
|
||||||
|
self.left = MicrobitCServo(self.left_pin)
|
||||||
|
self.right = MicrobitCServo(self.right_pin)
|
||||||
|
self.left.go = self.left.counterclockwise
|
||||||
|
self.right.go = self.right.clockwise
|
||||||
|
self.channel = 77
|
||||||
|
|
||||||
|
def forward(self):
|
||||||
|
self.left.go()
|
||||||
|
self.right.go()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.left.stop()
|
||||||
|
self.right.stop()
|
||||||
|
|
||||||
|
def go_left(self):
|
||||||
|
self.left.stop()
|
||||||
|
self.right.go()
|
||||||
|
microbit.display.show('a')
|
||||||
|
|
||||||
|
def go_right(self):
|
||||||
|
self.right.stop()
|
||||||
|
self.left.go()
|
||||||
|
microbit.display.show('b')
|
||||||
|
|
||||||
|
def radio_controlled(self):
|
||||||
|
radio.config(channel = self.channel)
|
||||||
|
radio.on()
|
||||||
|
while True:
|
||||||
|
order = radio.receive()
|
||||||
|
if order == 'go':
|
||||||
|
self.forward()
|
||||||
|
elif order == 'left':
|
||||||
|
self.go_left()
|
||||||
|
elif order == 'right':
|
||||||
|
self.go_right()
|
||||||
|
else:
|
||||||
|
self.stop()
|
||||||
|
|
||||||
|
car = RingCar()
|
||||||
|
car.radio_controlled()
|
16
ringbit_controller.py
Normal file
16
ringbit_controller.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# emetteur radio microbit
|
||||||
|
from microbit import *
|
||||||
|
import radio
|
||||||
|
|
||||||
|
radio.config(channel=77)
|
||||||
|
radio.on()
|
||||||
|
|
||||||
|
display.scroll('on')
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if button_a.is_pressed() and button_b.is_pressed():
|
||||||
|
radio.send('go')
|
||||||
|
elif button_a.is_pressed():
|
||||||
|
radio.send('left')
|
||||||
|
elif button_b.is_pressed():
|
||||||
|
radio.send('right')
|
Reference in New Issue
Block a user