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
- #green ⇒ Object
- #green_orange ⇒ Object
- #green_red ⇒ Object
-
#initialize(port = "/dev/tty.usbmodemfd121") ⇒ TrafficLight
constructor
A new instance of TrafficLight.
- #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 |
# 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 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
57 58 59 |
# File 'lib/traffic_light.rb', line 57 def all setColors(7) end |
#clear ⇒ Object
29 30 31 |
# File 'lib/traffic_light.rb', line 29 def clear setColors(0) end |
#green ⇒ Object
33 34 35 |
# File 'lib/traffic_light.rb', line 33 def green setColors(1) end |
#green_orange ⇒ Object
41 42 43 |
# File 'lib/traffic_light.rb', line 41 def green_orange setColors(3) end |
#green_red ⇒ Object
49 50 51 |
# File 'lib/traffic_light.rb', line 49 def green_red setColors(5) end |
#orange ⇒ Object
37 38 39 |
# File 'lib/traffic_light.rb', line 37 def orange setColors(2) end |
#orange_red ⇒ Object
53 54 55 |
# File 'lib/traffic_light.rb', line 53 def orange_red setColors(6) end |
#read ⇒ Object
19 20 21 |
# File 'lib/traffic_light.rb', line 19 def read @message = @sp.read.chomp end |
#red ⇒ Object
45 46 47 |
# File 'lib/traffic_light.rb', line 45 def red setColors(4) end |
#setColors(colors) ⇒ Object
23 24 25 26 27 |
# File 'lib/traffic_light.rb', line 23 def setColors(colors) read @sp.write colors read end |