Skip to content

Instantly share code, notes, and snippets.

@4noha
Created October 25, 2015 16:25
Show Gist options
  • Save 4noha/0a6799db27c23e7edffe to your computer and use it in GitHub Desktop.
Save 4noha/0a6799db27c23e7edffe to your computer and use it in GitHub Desktop.
require 'ftdi'
ctx = Ftdi::Context.new
begin
ctx.usb_open(0x0403, 0x6001)
begin
ctx.set_bitmode(0x01, :bitbang) #出力bit(1bit目のみ), bitbangモードの設定
loop do
puts "00000010".to_i(2) & ctx.read_pins == 0 #読みたいbitの指定
if "00000010".to_i(2) & ctx.read_pins == 0
ctx.write_data [0x01] #出力ビットを指定
else
ctx.write_data [0x00]
end
sleep 0.5
end
ensure
ctx.set_bitmode(0xff, :reset)
ctx.usb_close
end
rescue Ftdi::Error => e
$stderr.puts e.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment