Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- song_player program
- -- Function to play a note with a specific frequency and duration
- function playNote(freq, duration)
- speaker.playNote(freq, duration)
- os.sleep(duration * 0.5) -- Add a short delay between notes for rhythm
- end
- -- Function to play a song
- function playSong()
- -- Replace these notes and durations with the desired song
- local songNotes = {
- { note = "C5", duration = 0.5 },
- { note = "C5", duration = 0.5 },
- { note = "G5", duration = 0.5 },
- { note = "G5", duration = 0.5 },
- { note = "A5", duration = 0.5 },
- { note = "A5", duration = 0.5 },
- { note = "G5", duration = 1 },
- { note = "F5", duration = 0.5 },
- { note = "F5", duration = 0.5 },
- { note = "E5", duration = 0.5 },
- { note = "E5", duration = 0.5 },
- { note = "D5", duration = 0.5 },
- { note = "D5", duration = 0.5 },
- { note = "C5", duration = 1 }
- }
- for _, noteData in ipairs(songNotes) do
- playNote(noteData.note, noteData.duration)
- end
- end
- -- Call the playSong function to start playing the song
- playSong()
Advertisement
Add Comment
Please, Sign In to add comment