Files
LeonOS/data/computercraft/lua/rom/startup/50_audio.lua
Leonmmcoset 62d62ef14d feat(音频): 添加CC电脑启动音乐功能
添加简单的C大调音阶作为启动音乐,当检测到扬声器时自动播放
2025-09-01 16:56:35 +08:00

25 lines
665 B
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- LeonOS Startup Music
local rc = ...
local peripheral = require("peripheral")
local speaker = peripheral.find("speaker")
-- 检查是否连接了扬声器
if speaker then
-- 简单的开机音乐C大调音阶
local notes = {
{note = "C4", duration = 0.25},
{note = "D4", duration = 0.25},
{note = "E4", duration = 0.25},
{note = "F4", duration = 0.25},
{note = "G4", duration = 0.25},
{note = "A4", duration = 0.25},
{note = "B4", duration = 0.25},
{note = "C5", duration = 0.5}
}
-- 播放音乐
for _, note_info in ipairs(notes) do
speaker.playNote(note_info.note)
rc.sleep(note_info.duration)
end
end