@@ -256,6 +256,22 @@ impl DigitalOutputDevice {
256
256
}
257
257
}
258
258
259
+ pub struct RGBLED {
260
+ pub red : LED ,
261
+ pub green : LED ,
262
+ pub blue : LED ,
263
+ }
264
+
265
+ impl RGBLED {
266
+ pub fn new ( pin_red : u8 , pin_green : u8 , pin_blue : u8 ) -> RGBLED {
267
+ RGBLED {
268
+ red : LED :: new ( pin_red) ,
269
+ green : LED :: new ( pin_green) ,
270
+ blue : LED :: new ( pin_blue) ,
271
+ }
272
+ }
273
+ }
274
+
259
275
/// Represents a light emitting diode (LED)
260
276
///
261
277
/// # Example
@@ -740,7 +756,8 @@ impl Servo {
740
756
if value >= -1.0 && value <= 1.0 {
741
757
// Map value form [-1, 1] to [min_pulse_width, max_pulse_width] linearly
742
758
let range: f64 = ( self . max_pulse_width - self . min_pulse_width ) as f64 ;
743
- let pulse_width: u64 = self . min_pulse_width + ( ( ( value + 1.0 ) /2.0 ) * range) . round ( ) as u64 ;
759
+ let pulse_width: u64 =
760
+ self . min_pulse_width + ( ( ( value + 1.0 ) / 2.0 ) * range) . round ( ) as u64 ;
744
761
if self
745
762
. pin
746
763
. set_pwm (
@@ -751,12 +768,11 @@ impl Servo {
751
768
{
752
769
println ! ( "Failed to set servo to a new position" ) ;
753
770
}
754
- }
755
- else {
771
+ } else {
756
772
println ! ( "set_position value must be between -1 and 1" ) ;
757
773
}
758
774
}
759
-
775
+
760
776
/// Set the servo's minimum pulse width
761
777
pub fn set_min_pulse_width ( & mut self , value : u64 ) {
762
778
if value >= self . max_pulse_width {
@@ -796,12 +812,8 @@ impl Servo {
796
812
}
797
813
798
814
pub fn detach ( & mut self ) {
799
- if self
800
- . pin
801
- . clear_pwm ( )
802
- . is_err ( )
803
- {
815
+ if self . pin . clear_pwm ( ) . is_err ( ) {
804
816
println ! ( "Failed to detach servo" )
805
817
}
806
- }
818
+ }
807
819
}
0 commit comments