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
- #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 |
# 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 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
68 69 70 |
# File 'lib/traffic_light.rb', line 68 def all setColors(7) end |
#clear ⇒ Object
40 41 42 |
# File 'lib/traffic_light.rb', line 40 def clear setColors(0) end |
#close! ⇒ Object
25 26 27 28 |
# File 'lib/traffic_light.rb', line 25 def close! @sp.close @opened = false end |
#green ⇒ Object
44 45 46 |
# File 'lib/traffic_light.rb', line 44 def green setColors(1) end |
#green_orange ⇒ Object
52 53 54 |
# File 'lib/traffic_light.rb', line 52 def green_orange setColors(3) end |
#green_red ⇒ Object
60 61 62 |
# File 'lib/traffic_light.rb', line 60 def green_red setColors(5) end |
#open? ⇒ Boolean
21 22 23 |
# File 'lib/traffic_light.rb', line 21 def open? @opened end |
#orange ⇒ Object
48 49 50 |
# File 'lib/traffic_light.rb', line 48 def orange setColors(2) end |
#orange_red ⇒ Object
64 65 66 |
# File 'lib/traffic_light.rb', line 64 def orange_red setColors(6) end |
#read ⇒ Object
30 31 32 |
# File 'lib/traffic_light.rb', line 30 def read @message = @sp.read.chomp end |
#red ⇒ Object
56 57 58 |
# File 'lib/traffic_light.rb', line 56 def red setColors(4) end |
#setColors(colors) ⇒ Object
34 35 36 37 38 |
# File 'lib/traffic_light.rb', line 34 def setColors(colors) read @sp.write colors read end |