Skip to content

Commit

Permalink
emit :read/:write event #1
Browse files Browse the repository at this point in the history
  • Loading branch information
shokai committed Aug 7, 2013
1 parent ed246a2 commit 97aea48
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
14 changes: 9 additions & 5 deletions arduino/arduino.ino
Expand Up @@ -12,18 +12,22 @@ void setup(){
pinMode(PIN_LED, OUTPUT);
}

unsigned int analog_count = 0;
void loop(){
if(Serial.available()){
char recv = Serial.read();
process_input(recv);
}
else{
for(byte i = 0; i < 6; i++){
Serial.print("ANALOG");
Serial.println(i);
Serial.println(analogRead(i));
if(analog_count < 1){
for(byte i = 0; i < 6; i++){
Serial.print("ANALOG");
Serial.println(i);
Serial.println(analogRead(i));
}
}
delay(1000);
analog_count += 1;
if(analog_count > 65534) analog_count = 0;
}
}

Expand Down
9 changes: 7 additions & 2 deletions bin/arduino_ir_remote
Expand Up @@ -8,9 +8,14 @@ if ARGV.empty?
end

ir = IR::Remote.new ARGV.shift

ir.on :read do |data|
p data
end
ir.on :write do |data|
p data
end
ir.on :analog do |pin, value|
puts "#{pin} #{value}"
# puts "[analog#{pin}] #{value}"
end

last_ir_data = ""
Expand Down
9 changes: 8 additions & 1 deletion libs/ir_remote.rb
Expand Up @@ -32,7 +32,14 @@ def process_input(input)

case @state
when :read
emit :__ir_read, input if input =~ /^[\d,]+$/
if input =~ /^[\d,]+$/
emit :__ir_read, input
emit :read, input
end
when :write
if input =~ /^[\d,]+$/
emit :write, input
end
when /^ANALOG\d+$/
if input =~ /^\d+$/
emit :analog, @state.scan(/(\d+)$/)[0][0].to_i, input.to_i
Expand Down

0 comments on commit 97aea48

Please sign in to comment.