Can't use screen AND motors ?
See original GitHub issue- **ev3dev version: 4.4.32-17-ev3dev-ev3
- **ev3dev-lang-python version: python_ev3dev-0.8.0.post4-py2.7.egg (not sure this is what’s wanted)
Hi,
I can’t figure what the problem is with my code : I want to calibrate my light sensor, in order to follow a black line. I want the robot to oscillate 4 times, so that the sensor can update the max_white and max_black values. I have succeeded using the lcd screen and the motors, but separately. If I put all my functions in the same file, it will not work, but if I use the functions in different files, the code works. In fact, the motors will run, but the display isn’t even changed from its original state, and the values are not updated.
I am not exactly sure if it’s a bug somewhere, or if it’s due to my very beginner level in programming.
Here is my code :
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from ev3dev.ev3 import *
from PIL import ImageFont
from threading import Thread
from time import sleep
lcd = Screen()
globalstop = 0
ts = TouchSensor()
color_sensor = ColorSensor()
color_sensor.mode='COL-REFLECT'
motor_left = LargeMotor('outB')
motor_right = LargeMotor('outC')
f = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Arial.ttf', 15)
max_white = 0
max_black = 100
def motors():
global globalstop
sleep(0.5)
for i in range(4):
if i % 2 == 0:
motor_right.run_to_rel_pos(position_sp=180, speed_sp=200, stop_action='brake')
motor_left.run_to_rel_pos(position_sp=-180, speed_sp=200, stop_action='brake')
motor_right.wait_while('running')
motor_left.wait_while('running')
else:
motor_right.run_to_rel_pos(position_sp=-180, speed_sp=200, stop_action='brake')
motor_left.run_to_rel_pos(position_sp=180, speed_sp=200, stop_action='brake')
motor_right.wait_while('running')
motor_left.wait_while('running')
print (i+1)
globalstop = 1
motors = Thread(target=motors())
def display_and_update():
global max_white, max_black, globalstop
while globalstop == 0:
lcd.clear()
lcd.draw.text((10, 10), "max_white : %s" % max_white,font=f)
lcd.draw.text((10, 40), "max_black : %s" % max_black,font=f)
lcd.update()
if max_white < color_sensor.value():
max_white = color_sensor.value()
if max_black > color_sensor.value():
max_black = color_sensor.value()
disp_and_update = Thread(target=display_and_update())
#start the threads
motors.start()
disp_and_update.start()
#finally, output the values
print ("max_white : ", max_white, "max_black : ", max_black)
Any help appreciated !
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
How do you fix the touch screen in a car? - Jerry
Reboot the touchscreen by turning it off and back on again; Recalibrate the screen from the settings menu; Perform a factory reset. If...
Read more >8 Best Ways to Fix Android Auto Black Screen Issue
The Android Auto black screen issue has plagued several users. Are you one of them? If yes, here are some solutions to fix...
Read more >Car display screen unresponsive. Touchscreen lockout
Your browser can't play this video. ... Car display screen unresponsive. ... Seafoam-- can't believe what it did to my engine !! Project...
Read more >How To Fix A Touch Screen Car Stereo - Motorist Care
Step 1: Remove The Car Stereo · Step 2: Dissemble The Car Stereo · Step 3: Detach The Main Wires Of The Screen...
Read more >How to Reboot Your Car's Infotainment System
Press and hold the Back button, the Nav button, and the Mute button for at least 10 seconds.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There is a demo project that uses threads here: https://github.com/rhempel/ev3dev-lang-python/blob/develop/demo/R3PTAR/r3ptar.py.
OpenRoberta, specifically. But if
openroberta.service
is not running, it is free.