Skip to content

Instantly share code, notes, and snippets.

@rin
Created October 25, 2014 10:42
Show Gist options
  • Save rin/3d96fb6bebf118ed8383 to your computer and use it in GitHub Desktop.
Save rin/3d96fb6bebf118ed8383 to your computer and use it in GitHub Desktop.
Using Dino to control a vibrator
require 'bundler/setup'
require 'dino'
OUTPUT_PIN = 9
module Dino
module Components
class Vibrator < BaseComponent
def output(value)
analog_write(self.pin, value)
end
def stop
output(0)
end
end
end
end
board = Dino::Board.new(Dino::TxRx::Serial.new)
vibrator = Dino::Components::Vibrator.new(pin: OUTPUT_PIN, board: board)
5.times do
30.times do |value|
vibrator.output(value * 10)
sleep 0.1
end
end
vibrator.stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment