from finch import Finch
#Here we start using the robot
robot = Finch()

notes = [880, 988, 523, 587, 659, 698]
length = 1.2  #let's use a default length of the note

for note in notes:
    print("Note is", note)

    #QUESTION: What happens if I *remove* the indentation for the next line?
    robot.buzzer_with_delay(length, note)

print("The last note was ", note)
print("All notes played!")
Ejemplo n.º 2
0
from finch import Finch
#Here we start using the robot
robot = Finch()

length = 1.2  #let's use a default length of the note
stop_playing = False

while stop_playing is False:

    robot.buzzer_with_delay(length, 588)
    #pause for a minute
    stop = input(
        "Do you want to stop? Enter Y to stop playing. Enter anything else to continue playing"
    )
    if stop == 'Y':
        stop_playing = True

    if stop_playing is True:
        robot.buzzer_with_delay(length, 670)
        # QUESTION: What happens if I *remove* the indentation for the next two lines?
        robot.buzzer_with_delay(length, 670)
        robot.buzzer_with_delay(length, 670)
Ejemplo n.º 3
0
notes = ['A','a','B','b','C','c','D','d','E','e','F','f','A','a']

for note in notes:
    print("Note is", note)
    if (note.isupper()):
        length = 1.2  # uppercase letters mean long notes
    else:
        length = 0.6  # lowercase are short

    #convert note to lowercase so that we can compare easily
    current_note = note.lower() 

    if (current_note == 'a'):
        frequency = 880  
    elif (current_note == 'b'):
        frequency = 988
    elif (current_note == 'c'):
        frequency = 523
    elif (current_note == 'd'):
        frequency = 587
    elif (current_note == 'e'):
        frequency = 659
    elif (current_note == 'f'):
        frequency = 698
    else: #QUESTION: What happens if I de-indent this and the following lines?
        print("can't play this frequency!")
    print("Frequency is", frequency)
    #QUESTION: What happens if I *remove* the indentation for the next line?
    robot.buzzer_with_delay(length, frequency)

Ejemplo n.º 4
0
line = fp.readline()
while line:
    line.strip()
    if line.startswith("#"):
        print("comment")
        line = fp.readline()
        continue

    left = random.uniform(-0.5, 0.5)
    right = random.uniform(-0.5, 0.5)
    print("L:" + str(left), "R:" + str(right))
    finch.wheels(left, right)

    red = random.randint(0, 255)
    green = random.randint(0, 255)
    blue = random.randint(0, 255)
    print(red, green, blue)
    finch.led(red, green, blue)

    line.replace(" ", "")

    things = line.split(",")
    if things[0] == "T":
        finch.buzzer_with_delay(
            int(float(things[2])) / 1000, int(float(things[1])))
    if things[0] == "D": sleep(int(float(things[1])) / 1000)

    print(line)
    line = fp.readline()

fp.close()