Skip to content

Commit e7e4f93

Browse files
Added Motion Sensors
1 parent eda2888 commit e7e4f93

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

electroblocks/core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def config_digital_read(self, pin):
6363

6464
def digital_read(self, pin):
6565
return self._find_sensor_str(pin, "dr") == "1"
66+
67+
# Motion Sensors
68+
def config_motion_sensor(self, echoPin, trigPin):
69+
self._send(f"config:m={echoPin},{trigPin}")
70+
71+
def motion_distance_cm(self):
72+
return self._find_sensor_str("0", "m")
6673

6774
# Button Methods
6875
def config_button(self, pin):

motion_sensor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#Import ElectroBlocks library
2+
from electroblocks import ElectroBlocks
3+
import time # imports the time library
4+
5+
6+
# Variable Declaration
7+
8+
9+
# Initialise the program settings and configurations
10+
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
11+
eb.config_motion_sensor(10, 11) # Echo and Trig
12+
13+
for _ in range(1, 4):
14+
cm = eb.motion_distance_cm()
15+
print(f"Distance: {cm} centimeters")
16+
time.sleep(1)
17+
print("CONTINUE")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "electroblocks"
7-
version = "0.1.8"
7+
version = "0.1.9"
88
description = "Python client library to interact with ElectroBlocks Arduino firmware"
99
authors = [
1010
{ name = "Noah Glaser", email = "your.email@example.com" }

0 commit comments

Comments
 (0)