EasyManua.ls Logo

SunFounder PiCrawler Kit - Page 54

Default Icon
141 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder PiCrawler Kit
from robot_hat import Ultrasonic
Then initialize the ultrasonic pins.
sonar = Ultrasonic(Pin("D2") ,Pin("D3"))
Here is the main program.
Read the distance detected by ultrasonic module and filter out the values less than 0 (When the ultrasonic
module is too far from the obstacle or cannot read the data correctly, distance<0 will appear).
When the distance is less than or equal to alert_distance (the threshold value set earlier, which is 10), play
the sound effect sign.wav. PiCrawler does turn left angle .
When the distance is greater than alert_distance, PiCrawler will move forward.
distance = sonar.read()
print(distance)
if distance < 0:
pass
elif distance <= alert_distance:
try:
music.sound_effect_threading('./sounds/sign.wav')
except Exception as e:
print(e)
crawler.do_action('turn left angle',3,speed)
time.sleep(0.2)
else :
crawler.do_action('forward', 1,speed)
time.sleep(0.2)
Note: You can add different sound effects or music to musics or sounds folder via Filezilla Software.
Note: Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook!
Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
Ready to explore and create with us? Click [] and join today!
50 Chapter 3. Play with Python

Other manuals for SunFounder PiCrawler Kit

Related product manuals