Skip to content

Commit e07cd75

Browse files
added analog read and changed name for config on analog write
1 parent e2bb803 commit e07cd75

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

analog_write.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Initialise the program settings and configurations
99
eb = ElectroBlocks(verbose=True) # Create an instance of the ElectroBlocks class
10-
eb.analog_config(6)
10+
eb.analog_write_config(6)
1111

1212
for i in range(1, 200):
1313
eb.analog_write(6, i)

digital_write.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Initialise the program settings and configurations
99
eb = ElectroBlocks(verbose=True) # Create an instance of the ElectroBlocks class
10-
eb.digital_config(13)
10+
eb.digital_write_config(13)
1111
for _ in range(1, 10):
1212
eb.digital_write(13, 1)
1313
time.sleep(1)

electroblocks/core.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ComponentPins(Enum):
2424
RFID = 18,
2525
TEMP = 19,
2626
THERMISTOR = 20
27+
ANALOG_WRITE = 21
2728

2829

2930
class ElectroBlocks:
@@ -145,14 +146,7 @@ def _send(self, cmd):
145146
self.ser.write((cmd + "|\n").encode())
146147
self._wait_for_message("OK")
147148

148-
# Digital Write Method
149-
def config_digital_read(self, pin):
150-
self._add_pin(ComponentPins.DIGITAL_READ, pin)
151-
self._send(f"register::dr::{pin}")
152149

153-
def digital_read(self, pin):
154-
return self._find_sensor_str(pin, "dr") == "1"
155-
156150
# RFID
157151
def config_rfid(self, rxPin, txPin):
158152
self._add_pin(ComponentPins.RFID, rxPin)
@@ -279,8 +273,8 @@ def set_color_rgbled(self, r, g, b):
279273

280274
# LCD Methods
281275
def config_lcd(self, rows=2, cols=16, addr=39):
282-
self._add_pin(ComponentPins.DIGITAL_WRITE, "A5")
283-
self._add_pin(ComponentPins.DIGITAL_WRITE, "A4")
276+
self._add_pin(ComponentPins.LCD, "A5")
277+
self._add_pin(ComponentPins.LCD, "A4")
284278
self._send(f"register::lcd::{rows}::{cols}::{addr}")
285279

286280
def lcd_print(self, row, col, message):
@@ -307,9 +301,21 @@ def lcd_scrollright(self):
307301
def lcd_scrollleft(self):
308302
self._send("write::lcd::A5::7")
309303

310-
# LED Methods
304+
# Pins
305+
306+
def analog_write_config(self, pin):
307+
self._send(f"register::aw::{pin}")
308+
self._add_pin(ComponentPins.ANALOG_WRITE, pin)
309+
310+
def analog_read_config(self, pin):
311+
self._send(f"register::ar::{pin}")
312+
self._add_pin(ComponentPins.ANALOG_WRITE, pin)
313+
314+
def config_digital_read(self, pin):
315+
self._add_pin(ComponentPins.DIGITAL_READ, pin)
316+
self._send(f"register::dr::{pin}")
311317

312-
def digital_config(self, pin):
318+
def digital_write_config(self, pin):
313319
self._add_pin(ComponentPins.DIGITAL_WRITE, pin)
314320
self._send(f"register::dw::{pin}")
315321

@@ -319,9 +325,13 @@ def digital_write(self, pin, value):
319325
def analog_write(self, pin, value):
320326
self._send(f"write::aw::{pin}::{value}")
321327

322-
def analog_config(self, pin):
323-
self._send(f"register::aw::{pin}")
324-
self._add_pin(ComponentPins.ANALOG_WRITE, pin)
328+
329+
def digital_read(self, pin):
330+
return self._find_sensor_str(pin, "dr") == "1"
331+
332+
def analog_read(self, pin):
333+
return self._find_sensor_str(pin, "ar")
334+
325335

326336
# LED MATRIX
327337

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.15"
7+
version = "0.1.16"
88
description = "Python client library to interact with ElectroBlocks Arduino firmware"
99
authors = [
1010
{ name = "Noah Glaser", email = "[email protected]" }

0 commit comments

Comments
 (0)