Skip to content

Initial code changes after linting #142

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 28 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lint examples
  • Loading branch information
chrisruk committed Apr 20, 2022
commit 51eeeaed3a7e03875ae8862aa504ffe6fe8c23b7
8 changes: 6 additions & 2 deletions docs/buildhat/distance.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
from signal import pause
from buildhat import Motor, DistanceSensor

from buildhat import DistanceSensor, Motor

motor = Motor('A')
dist = DistanceSensor('D', threshold_distance=100)

print("Wait for in range")
dist.wait_for_in_range(50)
motor.run_for_rotations(1)
motor.run_for_rotations(1)

print("Wait for out of range")
dist.wait_for_out_of_range(100)
motor.run_for_rotations(2)


def handle_in(distance):
print("in range", distance)


def handle_out(distance):
print("out of range", distance)


dist.when_in_range = handle_in
dist.when_out_of_range = handle_out
pause()
8 changes: 6 additions & 2 deletions docs/buildhat/force.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from signal import pause
from buildhat import Motor, ForceSensor

from buildhat import ForceSensor, Motor

motor = Motor('A')
button = ForceSensor('D', threshold_force=1)
Expand All @@ -14,14 +15,17 @@
print("Wait for button to be pressed")

button.wait_until_pressed()
motor.run_for_rotations(2)
motor.run_for_rotations(2)


def handle_pressed(force):
print("pressed", force)


def handle_released(force):
print("released", force)


button.when_pressed = handle_pressed
button.when_released = handle_released
pause()
5 changes: 3 additions & 2 deletions docs/buildhat/light.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from buildhat import Light
from time import sleep

from buildhat import Light

light = Light('A')

light.on()
sleep(1)
light.off()
light.off()
13 changes: 7 additions & 6 deletions docs/buildhat/matrix.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from buildhat import Matrix
import time
import random
import time

from buildhat import Matrix

matrix = Matrix('C')

matrix.clear(("red",10))
matrix.clear(("red", 10))
time.sleep(1)

matrix.clear()
time.sleep(1)

matrix.set_pixel((0,0), ("blue", 10))
matrix.set_pixel((2,2), ("red", 10))
matrix.set_pixel((0, 0), ("blue", 10))
matrix.set_pixel((2, 2), ("red", 10))
time.sleep(1)

while True:
out = [[(int(random.uniform(0,9)),10) for x in range(3)] for y in range(3)]
out = [[(int(random.uniform(0, 9)), 10) for x in range(3)] for y in range(3)]
matrix.set_pixels(out)
time.sleep(0.1)
6 changes: 4 additions & 2 deletions docs/buildhat/motor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from signal import pause
from buildhat import Motor
import time

from buildhat import Motor

motor = Motor('A')
motorb = Motor('B')


def handle_motor(speed, pos, apos):
print("Motor", speed, pos, apos)


motor.when_rotated = handle_motor
motor.set_default_speed(50)

Expand Down
5 changes: 2 additions & 3 deletions docs/buildhat/passivemotor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from buildhat import PassiveMotor
import time

from buildhat import PassiveMotor

motor = PassiveMotor('A')

print("Start motor")
motor.start()
time.sleep(3)
print("Stop motor")
motor.stop()