Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the startup sound sequence with varied volumes and pitches
- local soundSequence = {
- {instrument = "harp", volume = 1, pitch = 0.5}, -- Low pitch
- {instrument = "harp", volume = 1, pitch = 0.6}, -- Slightly higher pitch
- {instrument = "harp", volume = 1, pitch = 0.7}, -- Mid pitch
- {instrument = "harp", volume = 1, pitch = 0.8}, -- Higher pitch
- {instrument = "harp", volume = 1, pitch = 1}, -- Standard pitch
- {instrument = "harp", volume = 0.8, pitch = 0.8},-- Lower volume, higher pitch
- {instrument = "harp", volume = 0.8, pitch = 0.6},-- Lower volume, mid pitch
- {instrument = "harp", volume = 0.8, pitch = 0.4} -- Lower volume, lower pitch
- }
- -- Function to play a note with given volume and pitch
- local function playNoteWithParams(instrument, volume, pitch, duration)
- local speaker = peripheral.find("speaker")
- if not speaker then
- print("No speaker found!")
- return false
- end
- -- Play the note with specified parameters
- speaker.playNote(instrument, volume, pitch)
- sleep(duration)
- return true
- end
- -- Check if a speaker is attached
- local function checkSpeaker()
- local speaker = peripheral.find("speaker")
- if speaker then
- print("Speaker found!")
- return true
- else
- print("No speaker found!")
- return false
- end
- end
- -- Main program
- print("Checking for speaker...")
- if checkSpeaker() then
- print("Playing startup sound...")
- for i, sound in ipairs(soundSequence) do
- local duration = 0.4 -- Duration of each note
- if not playNoteWithParams(sound.instrument, sound.volume, sound.pitch, duration) then
- print("Failed to play note. Exiting.")
- return
- end
- end
- print("Sound playback completed.")
- else
- print("Please connect a speaker and try again.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement