#!/usr/bin/env ruby require 'rubygems' require 'serialport' # If the main monitor is off, the Arduino is also off because it is connected to # the USB hub inside the monitor. So, if the main monitor is off, the user can't # control the lights any more and the LED stripes are off too. abort unless File.exists?('/dev/ttyUSB0') # Create the serial connection and send the given command. SerialPort.open('/dev/ttyUSB0', 9600, 8, 1, SerialPort::NONE) do |s| command = ARGV.join(' ') if command == 'on' or command == 'off' puts 'all ' + command + '...' ['a', 'c', 'c', 'd'].each do |port| s.puts(command + ' ' + port) end s.puts('led ' + command) else s.puts(ARGV.join(' ')) end end