Skip to content

Commit 2f396eb

Browse files
Fixed Return Types for ir remote and fixed joystick
1 parent eab5de8 commit 2f396eb

File tree

5 files changed

+71
-28
lines changed

5 files changed

+71
-28
lines changed

electroblocks/core.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ def config_joystick(self, x, y, sw):
173173
def joystick_angle(self):
174174
pin = self.pins[ComponentPins.JOYSTICK][0]
175175
[pressed, angle, engaged] = self._find_sensor_str(pin, "js").split('-')
176-
return angle
176+
return float(angle)
177177

178178
def is_joystick_button_pressed(self):
179179
pin = self.pins[ComponentPins.JOYSTICK][0]
180180
[pressed, angle, engaged] = self._find_sensor_str(pin, "js").split('-')
181-
return pressed
181+
return pressed == "1"
182182

183183
def is_joystick_engaged(self):
184184
pin = self.pins[ComponentPins.JOYSTICK][0]
185185
[pressed, angle, engaged] = self._find_sensor_str(pin, "js").split('-')
186-
return pressed
186+
return engaged == "1"
187187

188188
# Temp
189189
def config_dht_temp(self, pin, type):
@@ -231,7 +231,10 @@ def ir_remote_has_sensed_code(self):
231231

232232
def ir_remote_get_code(self):
233233
pin = self.pins[ComponentPins.IR_REMOTE][0]
234-
return self._find_sensor_str(pin, "ir")
234+
command = self._find_sensor_str(pin, "ir")
235+
if (command == ''):
236+
return 0
237+
return int(command)
235238

236239
# Motion Sensors
237240
def config_motion_sensor(self, echoPin, trigPin):

examples/digital_sensor.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#Import ElectroBlocks library
2+
from electroblocks import ElectroBlocks
3+
import time # imports the time library
4+
5+
6+
# Initialise the program settings and configurations
7+
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
8+
eb.config_digital_read(8) # Set up digital read for pin 8.
9+
eb.digital_write_config(3)
10+
eb.digital_write_config(9)
11+
12+
13+
while True:
14+
if eb.digital_read(8) or eb.digital_read(7):
15+
eb.digital_write(3, 1) # Turns the led on
16+
else:
17+
eb.digital_write(3, 0) # Turns the led off
18+
19+
if eb.digital_read(8) and eb.digital_read(7):
20+
eb.digital_write(9, 1) # Turns the led on
21+
else:
22+
eb.digital_write(9, 0) # Turns the led off
23+
24+
time.sleep(0.2) # Wait for the given/defined seconds.

ir_remote.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
import time # imports the time library
44

55

6-
# Variable Declaration
7-
86
# Initialise the program settings and configurations
9-
eb = ElectroBlocks(verbose=True) # Create an instance of the ElectroBlocks class
10-
eb.config_ir_remote(2) # Configures the LCD Screen pins
11-
12-
for _ in range(1, 10):
13-
sensed_code = eb.ir_remote_has_sensed_code()
14-
code = eb.ir_remote_get_code()
15-
print(f"Sensed Code: {sensed_code} | Code: {code}")
16-
time.sleep(10)
17-
print("CONTINUE")
7+
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
8+
eb.config_ir_remote(2) # IR Remote Config
9+
eb.digital_write_config(8)
10+
eb.digital_write_config(7)
11+
12+
13+
14+
while True:
15+
if eb.ir_remote_has_sensed_code():
16+
if (eb.ir_remote_get_code() == 70):
17+
eb.digital_write(8, 1) # Turns the led on
18+
19+
if (eb.ir_remote_get_code() == 69):
20+
eb.digital_write(7, 1) # Turns the led on
21+
22+
23+
time.sleep(1) # Wait for the given/defined seconds.

joystick.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
#Import ElectroBlocks library
22
from electroblocks import ElectroBlocks
3-
import time # imports the time library
43

4+
# Initialise the program settings and configurations
5+
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
6+
eb.config_joystick("A1", "A3", 9) # Configures the joystick
7+
eb.digital_write_config(7)
8+
eb.digital_write_config(8)
9+
eb.digital_write_config(13)
510

6-
# Variable Declaration
711

8-
# Initialise the program settings and configurations
9-
eb = ElectroBlocks(verbose=True) # Create an instance of the ElectroBlocks class
10-
eb.config_joystick("A1", "A3", 9) # Configures the LCD Screen pins
1112

12-
for _ in range(1, 10):
13-
button_pressed = eb.is_joystick_button_pressed()
14-
angle = eb.joystick_angle()
15-
is_engaged = eb.is_joystick_engaged()
16-
print(f"Engaged: {is_engaged} | Angle: {angle} | Button Pressed: {button_pressed}")
17-
time.sleep(2)
18-
print("CONTINUE")
13+
while True:
14+
if eb.is_joystick_button_pressed():
15+
eb.digital_write(7, 1) # Turns the led on
16+
else:
17+
eb.digital_write(7, 0) # Turns the led off
18+
19+
if (eb.joystick_angle() < 100):
20+
eb.digital_write(8, 0) # Turns the led off
21+
22+
if (eb.joystick_angle() > 100):
23+
eb.digital_write(8, 1) # Turns the led on
24+
25+
if eb.is_joystick_engaged():
26+
eb.digital_write(13, 1) # Turns the led on
27+
else:
28+
eb.digital_write(13, 0) # Turns the led off

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.20"
7+
version = "0.1.21"
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)