def __init__(self): self.adc = ads1x15.ADS1X15(ic=ads1x15.IC_ADS1115) self.pga = 6144 self.sps = 250 self._monitor_process = None self._continue_process = Value('b', False)
def __init__(self, channels=DEFAULT_CHANNELS, voltage=DEFAULT_VOLTAGE, sps=DEFAULT_SPS): self.adc = ads1x15.ADS1X15(ic=ads1x15.IC_ADS1115) self.channels = channels self.voltage = float(voltage) self.sps = sps if len(channels) > 2: raise ValueError, "Proximity: only two channels are supported"
def main(args): pwm = pca9685.PCA9685() pwm.reset() adc = ads1x15.ADS1X15(ic=ads1x15.IC_ADS1115) steps = int(1 + 4096 / 30.) program = [[0.000, [[c, 0, 0] for c in range(pca9685.CHANNELS)]] for _ in range(steps)] # compress the range of 0-full from N/16 to 1 scaled to steps # 0 if step/steps < N/16 # (steps - (N/16)*steps (1 - N/16) for channel in range(16): channel_scaled = channel / 16. for step in range(steps): step_scaled = step / float(steps - 1) if step_scaled >= channel_scaled: program[step][1][channel] = channel, 0, int( round(4096 * (step_scaled - channel_scaled) / (1 - channel_scaled))) program = list(reversed(program)) readings = [] median_readings = 15 while True: #vcc = adc.read_single_ended(1, pga=6144, sps=128) distance = adc.read_single_ended(0, pga=1024, sps=1600) * 1024 / 3300. readings.append(distance) # Median filter if len(readings) == median_readings: readings.sort() distance = readings[median_readings / 2] readings = [] else: continue #print int(round(distance)), "cm" # , int(round(vcc)), "mv" #if abs(distance2 - distance) > 40: # print "[reject]" # #distance = 10000 # continue #else: # distance = (distance + distance2) / 2. # print on = 1 - min(max(distance - 20, 0) / 110., 1.) step = int(round((len(program) - 1) * on)) print int(round(distance)), "cm", on
def main(args): if len(args) <= 0: print >> sys.stderr, "usage:", sys.argv[ 0], "<channel>", "[channel]", "[...]" return channels = map(int, args) or [0] adc = ads1x15.ADS1X15(ic=ads1x15.IC_ADS1115) while True: print "\t".join( str(round(read(adc, channel))) for channel in channels), " " * 70, "\r", sys.stdout.flush()
BUTTON_LONG_PRESS_COMMAND = "sh" BUTTON_LONG_PRESS_SCRIPT = "run_attention.sh" BUTTON_LONG_PRESS_ARGS = [""] PATH = os.path.dirname(__file__) script_path = os.path.join(PATH, BUTTON_SCRIPT) script_arg = [BUTTON_COMMAND, script_path] + BUTTON_ARGS long_press_script_path = os.path.join(PATH, BUTTON_LONG_PRESS_SCRIPT) long_press_script_arg = [BUTTON_LONG_PRESS_COMMAND, long_press_script_path ] + BUTTON_LONG_PRESS_ARGS process = None adc = ads1x15.ADS1X15(ic=ads1x15.IC_ADS1115) down = False down_time = 0 def main(): global down while True: try: value = adc.read_single_ended(3) if value > 3000: if not down: down_time = time() down = True
def __init__(self, channel=1): self.adc = ads1x15.ADS1X15(ic=ads1x15.IC_ADS1115) self.channel = channel
def __init__(self, voltage=DEFAULT_VOLTAGE): self.voltage = voltage self.adc = ads1x15.ADS1X15(ic=ads1x15.IC_ADS1115)