CallistoPastebin

Untitled

Aug 2nd, 2023
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. -- song_player program
  2.  
  3. -- Function to play a note with a specific frequency and duration
  4. function playNote(freq, duration)
  5. speaker.playNote(freq, duration)
  6. os.sleep(duration * 0.5) -- Add a short delay between notes for rhythm
  7. end
  8.  
  9. -- Function to play a song
  10. function playSong()
  11. -- Replace these notes and durations with the desired song
  12. local songNotes = {
  13. { note = "C5", duration = 0.5 },
  14. { note = "C5", duration = 0.5 },
  15. { note = "G5", duration = 0.5 },
  16. { note = "G5", duration = 0.5 },
  17. { note = "A5", duration = 0.5 },
  18. { note = "A5", duration = 0.5 },
  19. { note = "G5", duration = 1 },
  20. { note = "F5", duration = 0.5 },
  21. { note = "F5", duration = 0.5 },
  22. { note = "E5", duration = 0.5 },
  23. { note = "E5", duration = 0.5 },
  24. { note = "D5", duration = 0.5 },
  25. { note = "D5", duration = 0.5 },
  26. { note = "C5", duration = 1 }
  27. }
  28.  
  29. for _, noteData in ipairs(songNotes) do
  30. playNote(noteData.note, noteData.duration)
  31. end
  32. end
  33.  
  34. -- Call the playSong function to start playing the song
  35. playSong()
  36.  
Advertisement
Add Comment
Please, Sign In to add comment