Class: BrickPi::Motor
- Inherits:
-
Object
- Object
- BrickPi::Motor
- Defined in:
- lib/brick_pi/motor.rb
Instance Method Summary collapse
-
#initialize(port) ⇒ Motor
constructor
A new instance of Motor.
-
#position ⇒ Object
Encoder reads the position of the motor in .5-degree increments, Divide by 2 to get degrees.
- #spin(speed) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port) ⇒ Motor
Returns a new instance of Motor.
3 4 5 6 |
# File 'lib/brick_pi/motor.rb', line 3 def initialize(port) @port = port Native::MotorEnable[@port] = 1 end |
Instance Method Details
#position ⇒ Object
Encoder reads the position of the motor in .5-degree increments, Divide by 2 to get degrees
17 18 19 |
# File 'lib/brick_pi/motor.rb', line 17 def position Native::Encoder[@port] / 2 end |
#spin(speed) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/brick_pi/motor.rb', line 8 def spin(speed) speed = [-100, [100, speed].min].max motor_speed = (speed * 2.55).round puts motor_speed Native::MotorSpeed[@port] = motor_speed end |
#stop ⇒ Object
21 22 23 |
# File 'lib/brick_pi/motor.rb', line 21 def stop spin 0 end |