Advertisement
DOGGYWOOF

Untitled

Aug 5th, 2024 (edited)
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. -- Define the startup sound sequence with varied volumes and pitches
  2. local soundSequence = {
  3. {instrument = "harp", volume = 1, pitch = 0.5}, -- Low pitch
  4. {instrument = "harp", volume = 1, pitch = 0.6}, -- Slightly higher pitch
  5. {instrument = "harp", volume = 1, pitch = 0.7}, -- Mid pitch
  6. {instrument = "harp", volume = 1, pitch = 0.8}, -- Higher pitch
  7. {instrument = "harp", volume = 1, pitch = 1}, -- Standard pitch
  8. {instrument = "harp", volume = 0.8, pitch = 0.8},-- Lower volume, higher pitch
  9. {instrument = "harp", volume = 0.8, pitch = 0.6},-- Lower volume, mid pitch
  10. {instrument = "harp", volume = 0.8, pitch = 0.4} -- Lower volume, lower pitch
  11. }
  12.  
  13. -- Function to play a note with given volume and pitch
  14. local function playNoteWithParams(instrument, volume, pitch, duration)
  15. local speaker = peripheral.find("speaker")
  16. if not speaker then
  17. print("No speaker found!")
  18. return false
  19. end
  20.  
  21. -- Play the note with specified parameters
  22. speaker.playNote(instrument, volume, pitch)
  23. sleep(duration)
  24. return true
  25. end
  26.  
  27. -- Check if a speaker is attached
  28. local function checkSpeaker()
  29. local speaker = peripheral.find("speaker")
  30. if speaker then
  31. print("Speaker found!")
  32. return true
  33. else
  34. print("No speaker found!")
  35. return false
  36. end
  37. end
  38.  
  39. -- Main program
  40. print("Checking for speaker...")
  41. if checkSpeaker() then
  42. print("Playing startup sound...")
  43. for i, sound in ipairs(soundSequence) do
  44. local duration = 0.4 -- Duration of each note
  45. if not playNoteWithParams(sound.instrument, sound.volume, sound.pitch, duration) then
  46. print("Failed to play note. Exiting.")
  47. return
  48. end
  49. end
  50. print("Sound playback completed.")
  51. else
  52. print("Please connect a speaker and try again.")
  53. end
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement