Created
October 25, 2014 10:42
-
-
Save rin/3d96fb6bebf118ed8383 to your computer and use it in GitHub Desktop.
Using Dino to control a vibrator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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