-
Notifications
You must be signed in to change notification settings - Fork 31
Add simple Brickpi3 example #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| """ | ||
| The Brickpi3 doesn't support auto-detecting motors and sensors. To use devices | ||
| connected to the input ports, you must specify what type of device it is. | ||
| Output ports are pre-configured as NXT Large motors and do not need to be | ||
| configured manually. | ||
| """ | ||
|
|
||
| from time import sleep | ||
| from ev3dev2 import list_devices | ||
| from ev3dev2.port import LegoPort | ||
| from ev3dev2.motor import OUTPUT_A, LargeMotor, SpeedPercent | ||
| from ev3dev2.sensor import INPUT_1 | ||
| from ev3dev2.sensor.lego import UltrasonicSensor | ||
|
|
||
| p1 = LegoPort(INPUT_1) | ||
| # http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/brickpi3.html#brickpi3-in-port-modes | ||
| p1.mode = 'ev3-uart' | ||
| # http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/sensors.html#supported-sensors | ||
| p1.set_device = 'lego-ev3-us' | ||
|
|
||
| # allow for some time to load the new drivers | ||
| sleep(0.5) | ||
|
|
||
| s = UltrasonicSensor(INPUT_1) | ||
| m = LargeMotor(OUTPUT_A) | ||
|
|
||
| print("Running motor...") | ||
|
|
||
| while True: | ||
| dist = s.distance_centimeters | ||
| if dist < 50: | ||
| m.on(SpeedPercent(30)) | ||
| else: | ||
| m.on(SpeedPercent(-30)) | ||
dlech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| sleep(0.05) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.