Page 83 - Demo
P. 83

TI Python BootCamp Python LICHT, KLEUR & GELUID TI-INNOVATORTM TECHNOLOGIE
En dan nu de code voor Happy Birthday. De variabele tempo bepaalt de snelheid van afspelen. from ti_hub import *
from ti_system import * bday=speaker("BB 1")
def frequentie(x):
¨¨return 261.6*2**(x/12)
tempo=2
noot=recall_list("noot") tijd=recall_list("tijd")
for i in range(len(noot)): ¨¨bday.tone(frequentie(noot[i]),tijd[i]/tempo) ¨¨sleep(tijd[i]/tempo)
We eindigen met The Entertainer van Scott Joplin, gebruikmakend van nootnummers met als referentie C4 = 0.
    © 2020 T3 Nederland – T3 Vlaanderen
7 www.t3nederland.nl – www.t3vlaanderen.be
entertainer.py
from ti_hub import * from ti_system import *
muziek=speaker("BB 1") def frequentie(x):
¨¨return 261.6*2**(x/12) noot=recall_list("noot")
tijd=recall_list("tijd")
for i in range(len(noot)): ¨¨muziek.tone(frequentie(noot[i]),tijd[i]) ¨¨sleep(0.2*tijd[i])
 

















































































   81   82   83   84   85