Difference between revisions of "Flute.py"

From IPRE Wiki
Jump to: navigation, search
 
Line 14: Line 14:
  
 
# Play the flute for 60 seconds
 
# Play the flute for 60 seconds
while timeRemaining(60):
+
while timeRemaining(60):
  
 
     #get the values in the three light sensors
 
     #get the values in the three light sensors
Line 21: Line 21:
 
     # calculate the note selected
 
     # calculate the note selected
 
     note = 0
 
     note = 0
     if( lights[0] > THRESHOLD )
+
     if lights[0] > THRESHOLD:
 
         note += 1
 
         note += 1
     if( lights[1] > THRESHOLD )
+
     if lights[1] > THRESHOLD:
 
         note += 2
 
         note += 2
     if( lights[2] > THRESHOLD )
+
     if lights[2] > THRESHOLD:
 
         note += 4
 
         note += 4
 
     # have the scribbler play the note
 
     # have the scribbler play the note

Latest revision as of 18:52, 7 March 2011


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] )