Sha256: 5961176aa7e90aa2a2dfa3475b4113f88cee38cff30ece58d72e67f5acd819ef

Contents?: true

Size: 941 Bytes

Versions: 23

Compression:

Stored size: 941 Bytes

Contents

class Hysteresis < ArduinoPlugin
  
# jdbarnhart
# 20080728
#
#
# purpose
#
# add hysteresis to analog readings, typically sensors or potentiometers
#
# use
# two steps
#
#  one
#    declare :device => :sensor 
#    example:
#      input_pin 1, :as => :sensor_one, :device => :sensor
#
#  two
#    instead of:
#      my_lcd.print analogRead sensor_two
#      use add_hyst
#      my_lcd.print sensor_one.with_hyst 4
#      
#      # note, 4 is the amount of hysteresis
#
#
void with_hysteresis(int pin, int amt)
{
  with_hyst(pin, amt);
}

int with_hyst(int pin, int amt)
{
  int read;
  unsigned int i;
  read = analogRead(pin);
  for (i = 0; i < (int) (sizeof(hyst) / sizeof(hyst[0])); i++) {   
    if (pin == hyst[i].pin) {
      if (((read - hyst[i].state) > amt ) || ((hyst[i].state - read) > amt )) {
        hyst[i].state = read;
        return hyst[i].state;
      } 
      else
        return hyst[i].state;      
    }
  }
}



end

Version data entries

23 entries across 23 versions & 4 rubygems

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