Sha256: 6c137ae81650e9329aca4757b4214824e81304bac6a7820cbf728b631e6e5493

Contents?: true

Size: 901 Bytes

Versions: 23

Compression:

Stored size: 901 Bytes

Contents

ON = true
OFF = !ON
HIGH = ON
LOW = !HIGH

class ArduinoSketch
  attr_accessor :pins  
   
  def initialize
    @pins = self.class.instance_variable_get("@pins")
  end
  
  def self.output_pin(num, opts)
    module_eval "@pins ||= []"
    module_eval do 
      @pins <<  Pin.new( num, :type => :output )
    end

    if opts[:as]
       module_eval <<-CODE
         def #{opts[:as]}
           pins.select{|p| p.num == #{num}}.first
         end
       CODE
     end
  end

  def loop    
  end
  
  def digitalWrite( pin, value )
    to_change = pins.select{|p| p.num == pin.num}.first
    to_change.value = value
  end

  def delay( millis )
  end
  
  # def serial_read
  # end

  # def serial_available
  # end

  # def blink
  # end
end

class Pin
  attr_accessor :num, :type, :value

  def initialize num, opts
    @num = num
    @type = opts[:type]
    @value = opts[:value] || false
  end
end

Version data entries

23 entries across 23 versions & 4 rubygems

Version Path
neo_rad-0.4.0 lib/rad/sim/arduino_sketch.rb
atduskgreg-rad-0.2.5 lib/rad/sim/arduino_sketch.rb
atduskgreg-rad-0.3.0.1 lib/rad/sim/arduino_sketch.rb
atduskgreg-rad-0.3.1 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.2.6 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.2.7 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.3.1.1 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.3.1 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.3.2 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.3.3 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.3.4 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.3.5 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.3.6 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.3.7 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.3.8 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.3.9 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.4.0 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.5.0 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.4.3 lib/rad/sim/arduino_sketch.rb
madrona-rad-0.4.2 lib/rad/sim/arduino_sketch.rb