Ejemplo n.º 1
0
def main(csound_file):
    c = CosmoHat()
    try:
        while True:
            cs = csnd6.Csound()
            res = cs.Compile(csound_file)
            if res == 0:
                perf = csnd6.CsoundPerformanceThread(cs)
                perf.Play()
                try:
                    run(c, cs, perf)
                finally:
                    perf.Stop()
                    perf.Join()
                    break
            # Script stopped or didn't compile. Blink leds a couple of times
            on = {}
            off = {}
            for i in range(c.nleds):
                on[i] = True
                off[i] = False
            for i in range(5):
                for j in range(2):
                    c.set_leds(on)
                    sleep(0.1)
                    c.set_leds(off)
                    sleep(0.05)
                sleep(0.5)
    finally:
        c.stop()
Ejemplo n.º 2
0
def main():
    
    c = CosmoHat()
    print("Got version '{}'".format(c.version()))
    j = 0;

    knobs = list(c.knobs(raw=True))
    lowest = knobs[:]
    highest = knobs[:]
    
    while True:
        for i, knob in enumerate(c.knobs(raw=True)):
            lowest[i] = min(lowest[i], knob)
            highest[i] = max(highest[i], knob)
            print("knob {}: {:4} ({}-{})".format(i, int(knob), lowest[i], highest[i]))
        print("")
        for i, sw in enumerate(c.switches()):
            print("sw {}: {}".format(i, sw))
        print("")
        if c.nleds:
            for i in range(c.nleds):
                c.set_led(i, i == j)
            j = (j + 1) % c.nleds
        time.sleep(.5)
Ejemplo n.º 3
0
import time


def main(c):
    print("Got version '{}'".format(c.version()))
    i = 0
    while True:
        i += 1
        inputs = c.switches()
        #print(inputs)
        for i, nob in enumerate(c.nobs()):
            print("{}: ".format(i) + "=" * int(nob * 80))
        print("")
        c.set_leds(dict((i, inp) for i, inp in enumerate(inputs)))

        #adcs = c.adcs()
        #print("ADC:", adcs)
        time.sleep(0.05)


if __name__ == "__main__":
    c = CosmoHat(switches=[0, 1, 2, 3],
                 leds=[4, 7, 6, 5],
                 nobs=[(0, (8057, 0)), (1, (8056, 0)), (2, (8056, 0)),
                       (3, (8057, 0)), (4, (8056, 0)), (6, (8056, 0)),
                       (7, (8058, 0))])
    try:
        main(c)
    except KeyboardInterrupt:
        c.stop()