Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added demo for k8055 usb interface board
- Loading branch information
1 parent
48b5b4e
commit f9672b4
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env ruby | ||
require 'octopus' | ||
require 'rubyk8055' | ||
include USB | ||
|
||
@off_delay = 0.4 | ||
|
||
@r = RubyK8055.new | ||
@r.connect | ||
|
||
@r.clear_all_digital | ||
|
||
o = Octopus.new "/dev/ttyUSB0", 9600, 14 | ||
id_hash = {} | ||
|
||
while true | ||
id = o.read | ||
if channel = id_hash[id] | ||
@r.set_digital channel.to_i, false | ||
# Clears the channel after certain delay. | ||
Thread.new { sleep @off_delay; @r.set_digital channel.to_i, false } | ||
else | ||
print "Please enter a channel for this RFID tag '#{id}': " | ||
id_hash[id] = gets.chomp | ||
end | ||
end | ||
|