Esempio n. 1
1
    def __init__(self, display, pinmap, board = None, port = 0):
        self.display = display
        if board:
            self.board = board
        else:
            try:
                import pyk8055
                self.board = pyk8055.k8055(port)
            except:
                raise IOError("Could not establish a connection to the K8055 board.")

        self.reverse_pinmap = dict([(value, key) for key, value in pinmap.iteritems()])
        for pin, output in pinmap.iteritems():
            setattr(self, 'PIN_%s' % pin, output)
            if pin == 'LED':
                self.led_pwm = output > 8
Esempio n. 2
0
def main():
	k = pyk8055.k8055(0)
	old_counter = 0
	while True:
		value = k.ReadAnalogChannel(1)
		k.WriteAllDigital(value)
		time.sleep(0.1)
Esempio n. 3
0
def main():
	k = pyk8055.k8055(0)
	k.ResetCounter(1)
	k.ResetCounter(2)
	k.ClearAllDigital()
	stage = 0
	old_mask = 0
	while True:
		new_mask = k.ReadAllDigital()
		if new_mask != old_mask:
			if new_mask != 0:
				if new_mask == inputs_to_mask(COMBINATION[stage]):
					stage += 1
					k.SetDigitalChannel(stage)
				else:
					stage = 0
					k.ClearAllDigital()
				if stage == len(COMBINATION):
					print "Success!"
					for n in range(5):
						k.SetAllDigital()
						time.sleep(0.25)
						k.ClearAllDigital()
						time.sleep(0.25)
					for i in range(100):
						k.OutputAnalogChannel(1, i)
						k.OutputAnalogChannel(2, i)
					for i in range(100):
						k.OutputAnalogChannel(1, 100 - i)
						k.OutputAnalogChannel(2, 100 - i)
					return
			old_mask = new_mask
		time.sleep(0.1)
Esempio n. 4
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)

        # Initialize data
        self.x = arrayrange(0.0, 100.1, 0.5)
        self.a1 = zeros(len(self.x), Float)
        self.a2 = zeros(len(self.x), Float)

        self.setTitle("Simple K8055 datascope")
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend);

        self.curve1 = QwtPlotCurve("Input 1")
        self.curve2 = QwtPlotCurve("Input 2")

        self.curve1.attach(self)
        self.curve2.attach(self)

        self.curve1.setPen(QPen(Qt.red))
        self.curve2.setPen(QPen(Qt.green))

        # No automatic scaling, set y-scale 0-255
        self.setAxisScale(QwtPlot.yLeft,0,255,50)

        mY = Qwt.QwtPlotMarker()
        mY.setLineStyle(Qwt.QwtPlotMarker.HLine)
        mY.setYValue(128.0)
        mY.attach(self)

        self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)")
        self.setAxisTitle(QwtPlot.yLeft, "Values")

        self.startTimer(50)

        self.k = k8055(0)
Esempio n. 5
0
def run():
	k = pyk8055.k8055(0)
	pad = Keypad(k, cols = 3, rows = 4, keymap = KEYMAP)
	try:
		pad.read_loop()
	except KeyboardInterrupt:
		pass
	pad.reset()
Esempio n. 6
0
def do_write():
	k = pyk8055.k8055(0)
	f = open("levels.txt", 'w')
	try:
		while True:
			level = k.ReadAnalogChannel(1)
			f.write(str(level) + ";")
	except KeyboardInterrupt:
		f.close()
Esempio n. 7
0
def main():
	board = pyk8055.k8055(0)
	encoder = IncrementalEncoder(board)
	encoder.index = 1
	encoder.counter = 0
	try:
		encoder.event_loop()
	except KeyboardInterrupt:
		encoder.reset()
Esempio n. 8
0
def main():
	board = pyk8055.k8055(0)
	stepper = K8055StepperMotorController(board)
	
	try:
		rotate(stepper)
	except KeyboardInterrupt:
		time.sleep(1)
		stepper.reset()
Esempio n. 9
0
def main():
    board = pyk8055.k8055(0)
    stepper = K8055StepperMotorController(board)

    try:
        rotate(stepper)
    except KeyboardInterrupt:
        time.sleep(1)
        stepper.reset()
Esempio n. 10
0
def run():
	k = pyk8055.k8055(0)
	pad = StroboscopeKeypad(k, cols = 3, rows = 4, keymap = KEYMAP)
	strober = K8055Stroboscope(k, channel = 7)
	pad.strober = strober
	try:
		pad.read_loop()
	except KeyboardInterrupt:
		pass
	pad.reset()
Esempio n. 11
0
def main():
	board = pyk8055.k8055(0)
	stepper = K8055StepperMotorController(board, steps_per_revolution = 36)
	spectrum = Spectrum(stepper)
	thread.start_new_thread(spectrum.start, ())
	gobject.threads_init()
	loop = gobject.MainLoop()
	try:
		loop.run()
	except KeyboardInterrupt:
		stepper.reset()
Esempio n. 12
0
	def __init__(self):
		self.board = pyk8055.k8055(0)
		self.window = gtk.Window()
		self.window.connect('destroy', self.quit)
		self.window.set_title("K8055 control panel")
		self.window.set_border_width(10)
		self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
		self.icon = self.window.render_icon(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU)
		self.window.set_icon(self.icon)
		self.build_ui()
		gtk.timeout_add(100, self.update_from_board)
Esempio n. 13
0
def main():
	board = pyk8055.k8055(0)
	spectrum = MyAudioSpectrum(bands = 8, interval = 15000000)
	display = Display(board)
	spectrum.display = display
	
	thread.start_new_thread(display.update_loop, ())
	
	try:
		spectrum.start()
	except KeyboardInterrupt:
		display.stop()
Esempio n. 14
0
	def __init__(self):
		self.auto_strobe = False
		self.strobe_interval = 1.0
		self.board = pyk8055.k8055(0)
		self.window = gtk.Window()
		self.window.connect('destroy', self.quit)
		self.window.set_title("K8055 stroboscope control panel")
		self.window.set_border_width(10)
		self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
		self.icon = self.window.render_icon(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU)
		self.window.set_icon(self.icon)
		self.build_ui()
Esempio n. 15
0
def main():
	k = pyk8055.k8055(0)
	k.ResetCounter(1)
	k.ResetCounter(2)
	old_counter = 0
	while True:
		new_counter = k.ReadCounter(1) - k.ReadCounter(2)
		if new_counter != old_counter:
			k.WriteAllDigital(new_counter)
			k.OutputAnalogChannel(1, new_counter)
			k.OutputAnalogChannel(2, 255 - new_counter)
			old_counter = new_counter
		time.sleep(0.1)
Esempio n. 16
0
def main():
	board = pyk8055.k8055(0)
	display = K8055MatrixDisplayController(board, PIXMAP, ICONMAP)
	try:
		text = sys.argv[1].decode('utf-8')
	except IndexError:
		text = u"It works!"
	
	try:
		while True:
			display.write_text(text)
			continue
	except KeyboardInterrupt:
		display.stop()
Esempio n. 17
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)
        self.setCanvasBackground(Qt.white)

        # Initialize data
        self.x = arrayrange(0.0, 100.1, 0.5)
        self.d1 = 0.0 + zeros(len(self.x), Float)
        self.d2 = 1.0 + zeros(len(self.x), Float)
        self.d3 = 2.0 + zeros(len(self.x), Float)
        self.d4 = 3.0 + zeros(len(self.x), Float)
        self.d5 = 4.0 + zeros(len(self.x), Float)

        self.setTitle("Simple K8055 datascope")
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend);

        self.curve1 = QwtPlotCurve("Input 1")
        self.curve2 = QwtPlotCurve("Input 2")
        self.curve3 = QwtPlotCurve("Input 3")
        self.curve4 = QwtPlotCurve("Input 4")
        self.curve5 = QwtPlotCurve("Input 5")

        self.curve1.attach(self)
        self.curve2.attach(self)
        self.curve3.attach(self)
        self.curve4.attach(self)
        self.curve5.attach(self)

        self.curve1.setPen(QPen(Qt.red))
        self.curve2.setPen(QPen(Qt.blue))
        self.curve3.setPen(QPen(Qt.green))
        self.curve4.setPen(QPen(Qt.black))
        self.curve5.setPen(QPen(Qt.cyan))

        # Make data plot shape square
        self.curve1.setStyle(QwtPlotCurve.Steps)
        self.curve2.setStyle(QwtPlotCurve.Steps)
        self.curve3.setStyle(QwtPlotCurve.Steps)
        self.curve4.setStyle(QwtPlotCurve.Steps)
        self.curve5.setStyle(QwtPlotCurve.Steps)

        # Fixed axis here from 0 to 5
        self.setAxisScale(QwtPlot.yLeft,0,5,1)

        self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)")
        self.setAxisTitle(QwtPlot.yLeft, "Values")

        self.k = k8055(0)
        self.startTimer(50)
Esempio n. 18
0
def main():
	delay = float(sys.argv[1])
	k = pyk8055.k8055(0)
	while True:
		k.SetDigitalChannel(2)
		k.ClearDigitalChannel(4)
		time.sleep(delay)
		k.SetDigitalChannel(3)
		k.ClearDigitalChannel(5)
		time.sleep(delay)
		k.SetDigitalChannel(4)
		k.ClearDigitalChannel(2)
		time.sleep(delay)
		k.SetDigitalChannel(5)
		k.ClearDigitalChannel(3)
		time.sleep(delay)
Esempio n. 19
0
def main3():
	k = pyk8055.k8055(0)
	get_values(k)
	old_octave = 0
	all_frequencies = []
	all_durations = []
	try:
		while True:
			frequencies = []
			durations = []
			mask = VALUES[1]
			analog1 = VALUES[2]
			analog2 = float(VALUES[3])
			inputs = mask_to_bool_list(mask)
			true_inputs = float(len([input for input in inputs if input]))
			new_octave = divmod(analog1, 32)[0] + 1
			dur_mod = (analog2 / 127.0) ** 2
			thread.start_new_thread(get_values, (k, ))
			if new_octave != old_octave:
				k.ClearDigitalChannel(old_octave)
				k.SetDigitalChannel(new_octave)
				old_octave = new_octave
			if inputs[0]:
				frequencies.append(calculate_freq("C", new_octave, 0))
				durations.append((100.0 * dur_mod) / true_inputs)
			if inputs[1]:
				frequencies.append(calculate_freq("D", new_octave, 0))
				durations.append((100.0 * dur_mod) / true_inputs)
			if inputs[2]:
				frequencies.append(calculate_freq("E", new_octave, 0))
				durations.append((100.0 * dur_mod) / true_inputs)
			if inputs[3]:
				frequencies.append(calculate_freq("F", new_octave, 0))
				durations.append((100.0 * dur_mod) / true_inputs)
			if inputs[4]:
				frequencies.append(calculate_freq("G", new_octave, 0))
				durations.append((100.0 * dur_mod) / true_inputs)
			if mask > 0:
				beep(frequencies, durations)
				all_frequencies += frequencies
				all_durations += durations
	except KeyboardInterrupt:
		time.sleep(1)
		print "Replaying melody."
		beep(all_frequencies, all_durations)
Esempio n. 20
0
	def __init__(self):
		self.state = True
		self.light = 1
		self.sensitivity = 7.5
		self.sensitivity_multiplier = 1.0
		self.min_bass_interval = 0.35
		self.min_bass_interval_multiplier = 1.0
		self.last_bass = datetime.datetime.now()
		self.mode = MODE
		try:
			self.board = pyk8055.k8055(0)
			self.board.ClearAllAnalog()
			self.board.ClearAllDigital()
		except IOError:
			self.board = None
		if self.board:
			self.stepper = K8055StepperMotorController(self.board)
		class BassDetectorSpectrum(Spectrum):
			def on_data(self_, data):
				levels = [level + abs(self_.threshold) for level in data['magnitude']]
				if len(self_.last_levels) >= 50:
					self_.last_levels.pop(-1)
				self_.last_levels.insert(0, levels[0])
				avg = sum(self_.last_levels) / len(self_.last_levels)
				difference = levels[0] - avg
				
				if difference > (self.sensitivity * self.sensitivity_multiplier) and not self_.bass:
					self_.bass = True
					if not self.on_bass():
						return False
				
				if difference < (self.sensitivity * self.sensitivity_multiplier) and self_.bass:
					self_.bass = False
				
				if self_.bass and not self_.old_bass:
					if len(self_.basses) > 10:
						self_.basses.pop(0)
					self_.basses.append(datetime.datetime.now())
				
				if self_.bass != self_.old_bass:
					self_.old_bass = self_.bass
				return True
		
		self.spectrum = BassDetectorSpectrum()
Esempio n. 21
0
def main():
	k = pyk8055.k8055(0)
	get_values(k)
	while True:
		mask = VALUES[1]
		analog1 = float(VALUES[2])
		analog2 = float(VALUES[3])
		inputs = mask_to_bool_list(mask)
		freq_mod = (analog1 / 127.0) ** 2
		dur_mod = (analog2 / 127.0) ** 2
		thread.start_new_thread(get_values, (k, ))
		if inputs[0]:
			beep([100.0 * freq_mod], [100.0 * dur_mod])
		if inputs[1]:
			beep([200.0 * freq_mod], [100.0 * dur_mod])
		if inputs[2]:
			beep([300.0 * freq_mod], [100.0 * dur_mod])
		if inputs[3]:
			beep([400.0 * freq_mod], [100.0 * dur_mod])
		if inputs[4]:
			beep([500.0 * freq_mod], [100.0 * dur_mod])
Esempio n. 22
0
def main():
	k = pyk8055.k8055(0)
	sign = ledsign.LEDSign()
	sign.set_pages("K")
	old_mask = 0
	while True:
		mask = k.ReadAllDigital()
		if mask != old_mask:
			inputs = mask_to_bool_list(mask)
			if inputs[0]:
				sign.send([{'text': "Ponies"}], page = "K", lead_effect = 'twinkle', display_time = 0.5)
			elif inputs[1]:
				sign.set_brightness(1)
			elif inputs[2]:
				sign.set_brightness(2)
			elif inputs[3]:
				sign.set_brightness(3)
			elif inputs[4]:
				sign.set_brightness(4)
			old_mask = mask
		time.sleep(0.1)
Esempio n. 23
0
def main2():
	k = pyk8055.k8055(0)
	get_values(k)
	old_octave = 0
	while True:
		frequencies = []
		durations = []
		mask = VALUES[1]
		analog1 = VALUES[2]
		analog2 = float(VALUES[3])
		inputs = mask_to_bool_list(mask)
		true_inputs = float(len([input for input in inputs if input]))
		new_octave = divmod(analog1, 32)[0] + 1
		dur_mod = (analog2 / 127.0) ** 2
		thread.start_new_thread(get_values, (k, ))
		if new_octave != old_octave:
			k.ClearDigitalChannel(old_octave)
			k.SetDigitalChannel(new_octave)
			old_octave = new_octave
		if inputs[0]:
			frequencies.append(calculate_freq("C", new_octave, 0))
			durations.append((100.0 * dur_mod) / true_inputs)
		if inputs[1]:
			frequencies.append(calculate_freq("D", new_octave, 0))
			durations.append((100.0 * dur_mod) / true_inputs)
		if inputs[2]:
			frequencies.append(calculate_freq("E", new_octave, 0))
			durations.append((100.0 * dur_mod) / true_inputs)
		if inputs[3]:
			frequencies.append(calculate_freq("F", new_octave, 0))
			durations.append((100.0 * dur_mod) / true_inputs)
		if inputs[4]:
			frequencies.append(calculate_freq("G", new_octave, 0))
			durations.append((100.0 * dur_mod) / true_inputs)
		if len(frequencies) > 0:
			beep(frequencies, durations)
Esempio n. 24
0
def do_read():
	k = pyk8055.k8055(0)
	with open("levels.txt", 'r') as f:
		levels = f.read().split(";")[:-1]
	for level in levels:
		k.OutputAnalogChannel(1, int(level))
Esempio n. 25
0
def main():
    try:
        CYCLES = int(sys.argv[1])
    except:
        CYCLES = 1000
    k = pyk8055.k8055(0)
    k.ClearAllDigital()
    k.ClearAllAnalog()

    print "Test 1: Repeatedly setting and clearing all digital outputs at once"
    active = False
    start = datetime.datetime.now()
    for i in range(CYCLES + 1):
        if active:
            k.ClearAllDigital()
        else:
            k.SetAllDigital()
        active = not active
    stop = datetime.datetime.now()
    calculate_performance(start, stop, i, do_print=True)

    print "Test 2: Repeatedly setting and clearing one digital output"
    active = False
    channel = 1
    start = datetime.datetime.now()
    for i in range(CYCLES + 1):
        if active:
            k.ClearDigitalChannel(channel)
            channel = channel + 1 if channel < 8 else 1
        else:
            k.SetDigitalChannel(channel)
        active = not active
    stop = datetime.datetime.now()
    calculate_performance(start, stop, i, do_print=True)

    print "Test 3: Repeatedly setting and clearing all analog outputs at once"
    active = False
    start = datetime.datetime.now()
    for i in range(CYCLES + 1):
        if active:
            k.ClearAllAnalog()
        else:
            k.SetAllAnalog()
        active = not active
    stop = datetime.datetime.now()
    calculate_performance(start, stop, i, do_print=True)

    print "Test 4: Repeatedly incrementing and decrementing all analog outputs"
    value = 0
    down = False
    start = datetime.datetime.now()
    for i in range(CYCLES + 1):
        k.OutputAllAnalog(value, 255 - value)
        if down:
            if value > 0:
                value = value - 1
            else:
                down = False
                value = value + 1
        else:
            if value < 255:
                value = value + 1
            else:
                down = True
                value = value - 1
    stop = datetime.datetime.now()
    calculate_performance(start, stop, i, do_print=True)

    print "Test 5: Repeatedly reading all digital inputs at once"
    start = datetime.datetime.now()
    for i in range(CYCLES + 1):
        k.ReadAllDigital()
    stop = datetime.datetime.now()
    calculate_performance(start, stop, i, do_print=True)

    print "Test 5: Repeatedly reading all analog inputs at once"
    start = datetime.datetime.now()
    for i in range(CYCLES + 1):
        k.ReadAllAnalog()
    stop = datetime.datetime.now()
    calculate_performance(start, stop, i, do_print=True)
Esempio n. 26
0
	def __init__(self):
		self.auto_strobe = bool(sys.argv[2])
		self.strobe_interval = float(sys.argv[1])
		self.board = pyk8055.k8055(0)