From e618b2027a4f28338342be7a80167654df22f74b Mon Sep 17 00:00:00 2001 From: saho Date: Fri, 26 Jul 2024 17:35:05 +0900 Subject: [PATCH] param_led.py --- device/pi_led/pi_led/pi_led.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/device/pi_led/pi_led/pi_led.py b/device/pi_led/pi_led/pi_led.py index 08a0800..6643eae 100644 --- a/device/pi_led/pi_led/pi_led.py +++ b/device/pi_led/pi_led/pi_led.py @@ -10,9 +10,29 @@ def __init__(self): self._led_subscription = self.create_subscription( LedColor, "led_color", self.led_callback, 10 ) - self.led_r = LED("GPIO17") - self.led_g = LED("GPIO27") - self.led_b = LED("GPIO22") + param_r = self.declare_parameter("led_pin_r", "") + param_g = self.declare_parameter("led_pin_g", "") + param_b = self.declare_parameter("led_pin_b", "") + + pin_r = ( + self.get_parameter_or(param_r.name, param_r) + .get_parameter_value() + .integer_string + ) + pin_g = ( + self.get_parameter_or(param_g.name, param_g) + .get_parameter_value() + .integer_string + ) + pin_b = ( + self.get_parameter_or(param_b.name, param_b) + .get_parameter_value() + .integer_string + ) + + self.led_r = LED(pin_r) + self.led_g = LED(pin_g) + self.led_b = LED(pin_b) def led_callback(self, light: LedColor): self.led_light(self.led_r, light.red)