Flute.py

From IPRE Wiki
Revision as of 18:52, 7 March 2011 by Kjohara (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

from myro import *

init()
     
#define the 8 notees on the flute
notes = [440, 494, 554, 588, 659, 740, 831, 880]

# This constant defines the threshold for the light sensors.  A reading larger than
# this means the sensor is "closed".  You may need to adjust this depending on the ambient
# light levels in the room,
THRESHOLD = 2000

# Play the flute for 60 seconds
while timeRemaining(60):

    #get the values in the three light sensors
    lights = getLight()

    # calculate the note selected
    note = 0
    if lights[0] > THRESHOLD:
        note += 1
    if lights[1] > THRESHOLD:
        note += 2
    if lights[2] > THRESHOLD:
        note += 4
    # have the scribbler play the note
    beep( 0.2, notes[note] )