Skip to content

Commit 5497666

Browse files
committed
First commit of set_value() API
1 parent cf25945 commit 5497666

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

neobot/neosoco.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,24 @@ def _notify_sensory_device_data_changed(self):
333333
def _notify_motoring_device_data_changed(self):
334334
self._roboid._notify_motoring_device_data_changed()
335335

336+
def set_value(self, port: str, value: int):
337+
if isinstance(port, str) and isinstance(value, int):
338+
if port.lower() =='out1':
339+
self.write(Neosoco.OUTPUT_1, Util.round(value))
340+
elif port.lower() =='out2':
341+
self.write(Neosoco.OUTPUT_2, Util.round(value))
342+
elif port.lower() =='out3':
343+
self.write(Neosoco.OUTPUT_3, Util.round(value))
344+
elif port.lower() =='all':
345+
self.write(Neosoco.OUTPUT_1, Util.round(value))
346+
self.write(Neosoco.OUTPUT_2, Util.round(value))
347+
self.write(Neosoco.OUTPUT_3, Util.round(value))
348+
else:
349+
Util.print_error('Wrong value of port')
350+
raise ValueError
351+
else:
352+
raise TypeError
353+
336354
def get_value(self, port: str):
337355
if isinstance(port, str):
338356
if port.lower() =='in1':

test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
n = Neosoco()
44

55
# case1) Turn on LED with 100% brightness during 1s
6-
n.led_on("out1", '100')
6+
# n.led_on("out1", '100')
7+
# wait(1000)
8+
9+
n.set_value("out1", 255)
710
wait(1000)
811

912
# case2) Turn on LED when the distance is under 10cm

0 commit comments

Comments
 (0)