SunFounder PiCrawler Kit
No desktop !
*
Serving Flask app "vilib.vilib" (lazy loading)
*
Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
*
Debug mode: off
*
Running on http://0.0.0.0:9000/ (Press CTRL+C to quit)
Then you can enter http://<your IP>:9000/mjpg in the browser to view the video screen. such as: http:/
/192.168.18.113:9000/mjpg
Code
from picrawler import Picrawler
from time import sleep
from robot_hat import Music,TTS
from vilib import Vilib
import readchar
import random
import threading
crawler = Picrawler([10,11,12,4,5,6,1,2,3,7,8,9])
#crawler.set_offset([0,0,0,0,0,0,0,0,0,0,0,0])
music = Music()
tts = TTS()
manual = '''
Press keys on keyboard to control Picrawler!
w: Forward
a: Turn left
s: Backward
d: Turn right
space: Say the target again
esc: Quit
'''
color = "red"
color_list=["red","orange","yellow","green","blue","purple"]
key_dict = {
'w': 'forward',
's': 'backward',
'a': 'turn_left',
'd': 'turn_right',
}
def renew_color_detect():
global color
color = random.choice(color_list)
Vilib.color_detect(color)
tts.say("Look for " + color)
key = None
(continues on next page)
68 Chapter 3. Play with Python