Advertisement
LazerAio

YoutubePiano2ComputerCraftPiano.lua

Jul 7th, 2022
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. --Made by Aio in 2022
  2.  
  3. --Heres a fun one : 46511564
  4. --Another one: 410151337
  5. --To find multiple easily go to youtube and search for "youtube piano"
  6.  
  7. term.clear()
  8. print("IMPORTANT: before starting please install a regular speaker on the LEFT side")
  9. print("Please enter your notes")
  10. print("letters/chars for a longer momentary pause")
  11. print("HINT: use multiple chars for longer pauses")
  12. print("NOTE: this version does NOT support j/l commands")
  13. print("Example input:","123 65","will play C,D,E then A,G")
  14. Input = read()
  15. speak = peripheral.wrap("left")
  16. Chars = {}
  17. for i=1,string.len(Input) do
  18. Chars[#Chars+1] = string.sub(Input,i,i)
  19. end
  20. print("Now enter the desired 'delay time'")
  21. print("Enter any number (can be decimal)")
  22. print("Recomended for most cases: 0.4")
  23. delayTime = tonumber(read())
  24. term.clear()
  25. print("Notes:",Input)
  26. print("delay time",delayTime)
  27. print("Press enter to begin playing!")
  28. read()
  29. term.clear()
  30. function play(Chars,delayTime)
  31. for i=1,#Chars do
  32. term.setCursorPos(1,1)
  33. term.clear()
  34. print(#Chars-i)
  35. print(string.rep("=",10))
  36. print(string.rep("#",(i/#Chars)*10))
  37. sleep(delayTime)
  38. if tonumber(Chars[i]) == nil then
  39. sleep(delayTime-(delayTime/2))
  40. else --Play sound!
  41. note = tonumber(Chars[i])
  42. if note == 1 then
  43. speak.playNote("pling",100,6)
  44. elseif note == 2 then
  45. speak.playNote("pling",100,8)
  46. elseif note == 3 then
  47. speak.playNote("pling",100,10)
  48. elseif note == 4 then
  49. speak.playNote("pling",100,11)
  50. elseif note == 5 then
  51. speak.playNote("pling",100,13)
  52. elseif note == 6 then
  53. speak.playNote("pling",100,15)
  54. elseif note == 7 then
  55. speak.playNote("pling",100,17)
  56. elseif note == 8 then
  57. speak.playNote("pling",100,18)
  58. elseif note == 9 then
  59. speak.playNote("pling",100,20)
  60. elseif note == 0 then
  61. speak.playNote("pling",100,22)
  62. end
  63. end
  64. end
  65. end
  66. play(Chars,delayTime)
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement