Class: TrafficLight
- Inherits:
-
Object
- Object
- TrafficLight
- Defined in:
- lib/traffic_light.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
- #all ⇒ Object
- #blind=(value) ⇒ Object
- #blind? ⇒ Boolean
- #clear ⇒ Object
- #close! ⇒ Object
- #green ⇒ Object
- #green_orange ⇒ Object
- #green_red ⇒ Object
-
#initialize(port = "/dev/tty.usbmodemfd121") ⇒ TrafficLight
constructor
A new instance of TrafficLight.
- #open? ⇒ Boolean
- #orange ⇒ Object
- #orange_red ⇒ Object
- #read ⇒ Object
- #red ⇒ Object
- #setColors(colors) ⇒ Object
Constructor Details
#initialize(port = "/dev/tty.usbmodemfd121") ⇒ TrafficLight
Returns a new instance of TrafficLight.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/traffic_light.rb', line 6 def initialize(port="/dev/tty.usbmodemfd121") @port_str = port @baud_rate = 9600 @data_bits = 8 @stop_bits = 1 @parity = SerialPort::NONE @sp = SerialPort.new(@port_str, @baud_rate, @data_bits, @stop_bits, @parity) @sp.read_timeout = 1000 @opened = true @blind = false clear end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/traffic_light.rb', line 4 def @message end |
Instance Method Details
#all ⇒ Object
81 82 83 |
# File 'lib/traffic_light.rb', line 81 def all setColors(7) end |
#blind=(value) ⇒ Object
26 27 28 |
# File 'lib/traffic_light.rb', line 26 def blind=(value) @blind = value end |
#blind? ⇒ Boolean
30 31 32 |
# File 'lib/traffic_light.rb', line 30 def blind? @blind end |
#clear ⇒ Object
53 54 55 |
# File 'lib/traffic_light.rb', line 53 def clear setColors(0) end |
#close! ⇒ Object
34 35 36 37 |
# File 'lib/traffic_light.rb', line 34 def close! @sp.close @opened = false end |
#green ⇒ Object
57 58 59 |
# File 'lib/traffic_light.rb', line 57 def green setColors(1) end |
#green_orange ⇒ Object
65 66 67 |
# File 'lib/traffic_light.rb', line 65 def green_orange setColors(3) end |
#green_red ⇒ Object
73 74 75 |
# File 'lib/traffic_light.rb', line 73 def green_red setColors(5) end |
#open? ⇒ Boolean
22 23 24 |
# File 'lib/traffic_light.rb', line 22 def open? @opened end |
#orange ⇒ Object
61 62 63 |
# File 'lib/traffic_light.rb', line 61 def orange setColors(2) end |
#orange_red ⇒ Object
77 78 79 |
# File 'lib/traffic_light.rb', line 77 def orange_red setColors(6) end |
#read ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/traffic_light.rb', line 39 def read if blind? @message = "" else @message = @sp.read.chomp end end |
#red ⇒ Object
69 70 71 |
# File 'lib/traffic_light.rb', line 69 def red setColors(4) end |
#setColors(colors) ⇒ Object
47 48 49 50 51 |
# File 'lib/traffic_light.rb', line 47 def setColors(colors) read @sp.write colors read end |