Class: PwmPin
- Inherits:
-
Object
- Object
- PwmPin
- Defined in:
- lib/pwm_pin.rb
Constant Summary collapse
- PI_BLASTER_PATH =
"/dev/pi-blaster"
Instance Attribute Summary collapse
-
#pb_val ⇒ Object
readonly
Returns the value of attribute pb_val.
-
#pin_num ⇒ Object
readonly
Returns the value of attribute pin_num.
-
#pwm_file ⇒ Object
readonly
Returns the value of attribute pwm_file.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(pin_num) ⇒ PwmPin
constructor
A new instance of PwmPin.
-
#pwm_write(value) ⇒ Object
Writes PWM value to the specified pin Param value should be integer from 0 to 255.
- #release ⇒ Object
Constructor Details
#initialize(pin_num) ⇒ PwmPin
Returns a new instance of PwmPin.
7 8 9 10 11 12 |
# File 'lib/pwm_pin.rb', line 7 def initialize(pin_num) @pin_num = pin_num @pwm_file = File.open("#{ PI_BLASTER_PATH }", "w") pwm_write(0) end |
Instance Attribute Details
#pb_val ⇒ Object (readonly)
Returns the value of attribute pb_val.
3 4 5 |
# File 'lib/pwm_pin.rb', line 3 def pb_val @pb_val end |
#pin_num ⇒ Object (readonly)
Returns the value of attribute pin_num.
3 4 5 |
# File 'lib/pwm_pin.rb', line 3 def pin_num @pin_num end |
#pwm_file ⇒ Object (readonly)
Returns the value of attribute pwm_file.
3 4 5 |
# File 'lib/pwm_pin.rb', line 3 def pwm_file @pwm_file end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/pwm_pin.rb', line 3 def value @value end |
Instance Method Details
#pwm_write(value) ⇒ Object
Writes PWM value to the specified pin Param value should be integer from 0 to 255
16 17 18 19 20 21 22 23 24 |
# File 'lib/pwm_pin.rb', line 16 def pwm_write(value) @value = value # Calculates the pi-blaster required value between 0 and 1 inclusive @pb_val = pi_blaster_val(value) @pwm_file.write("#{ pin_num }=#{ @pb_val }\n") @pwm_file.flush end |
#release ⇒ Object
26 27 28 29 |
# File 'lib/pwm_pin.rb', line 26 def release @pwm_file.write("release #{ pin_num }\n") @pwm_file.flush end |