Skip to content

Commit 211ac94

Browse files
committed
Add color_led_on() API
1 parent e9cecb7 commit 211ac94

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

neopia/neosoco.py

+33
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,39 @@ def _write_to_output_port(self, port, out_val):
491491
else:
492492
raise ValueError('Wrong value of out port')
493493

494+
def color_led_on(self, port='out1', red=255, blue=0, green=0):
495+
if isinstance(port, str):
496+
if isinstance(red and blue and green, (int, float)):
497+
red = max(red, 1)
498+
red = min(red, 251)
499+
green = max(green, 1)
500+
green = min(green, 251)
501+
blue = max(blue, 1)
502+
blue = min(blue, 251)
503+
504+
# Red
505+
self._write_to_output_port(port, 252)
506+
Runner.wait(100)
507+
self._write_to_output_port(port, red)
508+
Runner.wait(100)
509+
# Green
510+
self._write_to_output_port(port, 253)
511+
Runner.wait(100)
512+
self._write_to_output_port(port, green)
513+
Runner.wait(100)
514+
# Blue
515+
self._write_to_output_port(port, 254)
516+
Runner.wait(100)
517+
self._write_to_output_port(port, blue)
518+
Runner.wait(100)
519+
# Accept
520+
self._write_to_output_port(port, 255)
521+
Runner.wait(100)
522+
else:
523+
raise TypeError
524+
else:
525+
raise TypeError
526+
494527
def led_on(self, port='out1', brightness='100'):
495528
percent_cvt = {
496529
'100': 255,

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="neopia",
5-
version="0.1.2",
5+
version="0.1.4",
66
author="RoboticsWare",
77
author_email="neopia.uz@google.ocm",
88
description="Python library for Neopia neobot",

test.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,8 @@
118118
# if n.check_color('in1', 'Green'):
119119
# n.led_on('out1', '100')
120120
# else:
121-
# n.led_off('out1')
121+
# n.led_off('out1')
122+
123+
# case 15) Turn on color LED with red color during 3s
124+
n.color_led_on('out1', 255, 0, 0)
125+
wait(3000)

0 commit comments

Comments
 (0)