Class: DebounceMethods

Inherits:
ArduinoSketch show all
Defined in:
lib/examples/debounce_methods.rb

Instance Attribute Summary

Attributes inherited from ArduinoSketch

#pins

Instance Method Summary collapse

Methods inherited from ArduinoSketch

#add, add_to_setup, #array, #assembler, #comment_box, #compose_setup, #define, #delay, #digitalWrite, #formatted_print, #initialize, #input_pin, #input_pins, output_pin, #output_pin, post_process_ruby_to_c_methods, pre_process, #serial_begin

Methods included from ExternalVariableProcessing

#c_type, #check_variable_type, #post_process_arrays, #post_process_vars, #pre_process_vars, #process_external_vars, #translate_variables

Constructor Details

This class inherits a constructor from ArduinoSketch

Instance Method Details



29
30
31
# File 'lib/examples/debounce_methods.rb', line 29

def blink_three_times
  3.times { led.blink 200 }
end

no blink helper



34
35
36
37
38
39
40
41
# File 'lib/examples/debounce_methods.rb', line 34

def blink_three_times_basic
  4.times do 
    led.on
    delay 200
    led.off
    delay 200
  end
end


23
24
25
26
27
# File 'lib/examples/debounce_methods.rb', line 23

def blink_twice
  2.times do |i|
    led.blink 200 + i
  end
end


43
44
45
46
47
# File 'lib/examples/debounce_methods.rb', line 43

def blink_with_a_twist
  20.times do |i|
    led.blink i * 10
  end
end

#loopObject

# depressing and releasing button_one, button_two or button_four do the same thing # with a slightly different syntax and number of blinks # button_three simply toggles the led with the read_and_toggle method # button_five does it with a twist



15
16
17
18
19
20
21
# File 'lib/examples/debounce_methods.rb', line 15

def loop
  blink_twice if read_input button_one
  blink_three_times if read_input button_two
  button_three.read_and_toggle led #  
  blink_three_times_basic if read_input button_four
  blink_with_a_twist if read_input button_five
end