import sys
import time

from gameduino import Gameduino, readarray
from GDprep import spectrum

gd = Gameduino(sys.argv[1], 115200)

gd.silence()

# gd.microcode(readarray("../j1firmware/helloworld.binle"))

for (i, (f, a)) in enumerate(spectrum("thx.txt", cutoff = 64, volume = 512)):
    print f
    # tunef = 392 * (f / 392.)
    for s in range(4):
        ea = ((s + 1) * a) / 4
        gd.voice(i, 0, int(4 * f * 1.0), ea, ea)
        time.sleep(.01)
time.sleep(60)
