0 Members and 1 Guest are viewing this topic.
TONE_LOW = "\001"TONE_HIGH = "\255"happy_birthday = {262,0.5,262,0.5,294,1,262,1,349,1,330,2,262,0.5,262,0.5,294,1,262,1,392,1,349,2,262,0.5,262,0.5,523,1,440,1,349,1,330,1,294,3,466,1,466,1,440,1,349,1,392,1,349,2}function freq_key(key) --return 440 * math.pow(2, (key-49)/12) return keyendfunction keytone(key) local am = 57600/freq_key(key) return TONE_HIGH:rep(am) .. TONE_LOW:rep(am)endfunction key_am(key, ammount) return keytone(key):rep(ammount)endfunction key_time(key, time) return key_am(key, freq_key(key)*time)endfunction play() local out = "" for i=1,#happy_birthday,2 do out = out..key_time(happy_birthday[i]*5, happy_birthday[i+1]/10) end print(out)endfunction on.timer() play() timer.stop()endfunction on.paint(gc) timer.start(1)end
function freq_key(key) --return 440 * math.pow(2, (key-49)/12) return keyendtofunction freq_key(key) return 440 * math.pow(2, (key-49)/12) --return keyend
t0xic, the problem is that I don't have full controlling of what I send. I'm using the print() function to send the data to the serial port (so at byte level). 001 is low, and 255 is high. So my wave form isn't perfect at all, but at least you can hear the tones @thepenguin77, thanks!