# main.py -- put your code here!
import machine
from machine import Pin
import time
left_pin1 = Pin(14,Pin.OUT)
left_pin2 = Pin(12,Pin.OUT)
right_pin1 = Pin(13,Pin.OUT)
right_pin2 = Pin(15,Pin.OUT)
Trig = Pin(5, Pin.OUT)
Echo = Pin(4, Pin.IN)
def Go():
left_pin1.value(1)
left_pin2.value(0)
right_pin1.value(1)
right_pin2.value(0)
def Back():
left_pin1.value(0)
left_pin2.value(1)
right_pin1.value(0)
right_pin2.value(1)
def Left():
left_pin1.value(1)
left_pin2.value(0)
right_pin1.value(0)
right_pin2.value(1)
def Right():
left_pin2.value(1)
left_pin1.value(0)
right_pin1.value(1)
right_pin2.value(0)
while True:
Trig.value(1)
time.sleep_us(20)
Trig.value(0)
while (Echo.value() == 0):
Trig.value(1)
time.sleep_us(20)
Trig.value(0)
if (Echo.value() == 1):
ts = time.ticks_us()
while (Echo.value() == 1):
ESP8266超声波避障小车1.0
最新推荐文章于 2023-01-09 11:25:33 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)