Open EloiStree opened 2 days ago
# Documentation https://github.com/EloiStree/HelloInput/issues/139
# Imports go at the top
from microbit import *
import time
bool_switch = False
display.off()
print("Hello...")
time.sleep(0.1)
print("World")
int_20000=20000
int_left=500
int_middle=1500
int_right=2500
def turn_left(pin):
pin.write_digital(1)
time.sleep_us(int_left)
pin.write_digital(0)
time.sleep_us(int_20000-int_left)
def turn_middle(pin):
pin.write_digital(1)
time.sleep_us(int_middle)
pin.write_digital(0)
time.sleep_us(int_20000-int_middle)
def turn_right(pin):
pin.write_digital(1)
time.sleep_us(int_right)
pin.write_digital(0)
time.sleep_us(int_20000-int_right)
output_pins = [
pin0,
pin1,
pin2,
pin3,#ND
pin4,#ND
pin6,#ND
pin7,#ND
pin8, #TX RX?
pin9,#ND
pin10, #ND
pin12, # RESERVED ? ACCESSIBILITY
pin13, # CLOCK
pin14, # SPI BUS
pin15, # SPI BUS
pin16, # CHIP SELECT
#pin5, BUTTON A INPUT EXTERNAL
#pin11, BUTTON B INPUT EXTERNAL
#pin17, # 3V for PAD
#pin18, # 3V for PAD
#pin19, # I2C COM
#pin20, # I2C COM
#pin21, #GROUND
#pin22, #GROUND
]
def turn_all_delay(ms):
for pin in output_pins:
pin.write_digital(1)
time.sleep_us(ms)
for pin in output_pins:
pin.write_digital(0)
time.sleep_us(int_20000-ms)
def turn_all_mid():
turn_all_delay(int_middle)
def turn_all_left():
turn_all_delay(int_left)
def turn_all_right():
turn_all_delay(int_right)
int_step=3
int_state_previous=0
int_state =-1
print("Middle Start")
for pin in output_pins:
for i in range(int_step):
turn_middle(pin)
while True:
int_state_previous=int_state
if button_a.was_pressed():
int_state+=-2
if button_b.was_pressed():
int_state+=2
if(pin_logo.is_touched()):
int_state=0
if int_state<-1:
int_state=-1
if int_state>1:
int_state=1
if int_state!=int_state_previous:
print("Turn Middle")
for pin in output_pins:
for i in range(int_step):
turn_middle(pin)
if int_state==-1:
print("Turn Left")
for pin in output_pins:
for i in range(int_step):
turn_left(pin)
if int_state==1:
print("Turn right")
for pin in output_pins:
for i in range(int_step):
turn_right(pin)
https://amzn.to/40vOYs6
https://www.upesy.fr/blogs/tutorials/esp32-servo-motor-sg90-with-arduino-code#:~:text=Comment%20piloter%20le%20servomoteur%20SG90,comprise%20entre%201ms%20et%202ms.
https://opencoursehub.cs.sfu.ca/bfraser/grav-cms/cmpt433/links/files/2022-student-howtos/ServoPWMGuide_SG90_9gMicroServo.pdf
https://robotix.ah-oui.org/user_docs/dos11/sg90-data.pdf