Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9d8cd9a
Added support for flipping encoder direction
SaintSampo Mar 14, 2025
ba8d945
Add conditional support for fourth motor based on hardware
SaintSampo Nov 19, 2025
04958ef
Update encoded_motor.py
SaintSampo Nov 19, 2025
6bb8050
Update reflectance.py
SaintSampo Nov 26, 2025
2435d3f
Merge pull request #1 from Open-STEM/main
SaintSampo Feb 23, 2026
07e2d26
Use sys.implementation, add encoder flip, fix encoder pin check
SaintSampo Mar 12, 2026
94daeae
Support NanoXRP drivetrain and encoder
SaintSampo Mar 12, 2026
600a411
Merge branch 'Open-STEM:main' into main
SaintSampo Mar 17, 2026
2140214
Guard middle reflectance pin; Updated docstring
SaintSampo Mar 23, 2026
3c2538f
Order encoder pins by numeric GPIO id
SaintSampo Mar 23, 2026
00e76ee
Merge pull request #93 from SaintSampo/NanoXRP
SaintSampo Mar 23, 2026
537b9ee
Adjust control/sensor behavior for NanoXRP
SaintSampo Apr 3, 2026
2a24ffb
Add Buzzer driver and include in defaults
SaintSampo Apr 4, 2026
c46f121
Fix gyro axis mapping for NanoXRP
SaintSampo Apr 4, 2026
bcd1e46
Merge branch 'main' into jacob-nanoxrp
SaintSampo Apr 6, 2026
8ba6e9f
Add buzzer examples and modernize Buzzer init
SaintSampo May 4, 2026
89fa5b8
Add buzzer reset and integrate into resetbot
SaintSampo May 4, 2026
d596014
Error on missing middle reflectance sensor
SaintSampo May 4, 2026
1f012ac
Non-blocking buzzer inter-note gap handling
SaintSampo May 5, 2026
9d0fc99
Clean up imports and fix flip_dir logic
SaintSampo May 5, 2026
cbc9cd9
Refactor IMU/Drive/Buzzer
SaintSampo May 5, 2026
0210cae
Refactor IMU/Drive/Buzzer
SaintSampo May 5, 2026
e5e57d5
Merge branch 'jacob-nanoxrp' of https://github.com/Open-STEM/XRP_Micr…
SaintSampo May 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions XRPExamples/buzzer_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from XRPLib.defaults import *
import time

"""
By the end of this file students will learn how to use the Buzzer class
to play individual notes, custom songs, and how to make the robot
play music while it is moving.
"""

def simple_scale():
"""Plays a basic C major scale."""
print("Playing a simple scale...")
notes = ["C4", "D4", "E4", "F4", "G4", "A4", "B4", "C5"]
for note in notes:
buzzer.play_note(note, "quarter")

def custom_song_example():
"""Demonstrates how to create and play a custom list of notes."""
print("Playing a custom melody...")
# A song is a list of (note, duration) tuples
# Durations can be "whole", "half", "quarter", "eighth", "sixteenth"
my_song = [
("E4", "eighth"), ("G4", "eighth"), ("E5", "quarter"),
("rest", "eighth"),
("C4", "quarter"), ("G3", "half")
]

# Set tempo to 140 Beats Per Minute
buzzer.set_tempo(140)
buzzer.play_song(my_song)

def siren():
"""Simple two-tone siren effect using individual notes."""
print("Siren started!")
for _ in range(3):
buzzer.play_note("A4", "quarter")
buzzer.play_note("E4", "quarter")

def musical_robot():
"""
Playing music while driving.
We use blocking=False so the code continues to the next line
while the music plays in the background.
"""
print("Dancing with music!")

# Start 'Move It' in the background
buzzer.play_move_it(blocking=False)

# While the song is playing, the robot can perform actions
for i in range(4):
drivetrain.set_effort(0.6, -0.6) # Spin right
time.sleep(0.5)
drivetrain.set_effort(-0.6, 0.6) # Spin left
time.sleep(0.5)

drivetrain.stop()
print("Dance finished.")

def drive_and_beep():
"""Driving forward and playing a note at the same time."""
# Start driving forward (this is non-blocking)
drivetrain.set_effort(0.5, 0.5)

# Play a long note (blocking=True) so the robot drives for the duration of the note
print("Driving for a whole note...")
buzzer.play_note("C5", "whole", blocking=True)

drivetrain.stop()

def main():
# Run the examples
simple_scale()
time.sleep(1)

siren()
time.sleep(1)

musical_robot()

main()
Loading