ITS_SELINASOON

MicroBit

Nov 4th, 2022
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. input.onButtonPressed(Button.A, function () {
  2.     if (iscooldown == true) {
  3.         return
  4.     }
  5.     i = Math.clamp(0,Infinity,i + 1)
  6. basic.showNumber(i)
  7.     while (true) {
  8.         wait(delta_time)
  9.         timepassed += delta_time
  10.         console.log(timepassed)
  11. if (timepassed >= cooldown) {
  12.             break;
  13.         }
  14.     }
  15.     timepassed = 0
  16.     iscooldown = false
  17. })
  18. function wait (second: number) {
  19.     n = second * 1000
  20.     basic.pause(n)
  21.     return n
  22. }
  23. input.onButtonPressed(Button.AB, function () {
  24.     timepassed = 0
  25.     timepassed2 = 0
  26.     i = 0
  27.     basic.showNumber(i)
  28.     for (let value of music_data) {
  29.         if (last_value == value) {
  30.             wait(delta_time)
  31.         }
  32.         music.playTone(value, music.beat(BeatFraction.Whole))
  33.         last_value = value
  34.     }
  35. })
  36. input.onButtonPressed(Button.B, function () {
  37.     if (iscooldown == true) {
  38.         return
  39.     }
  40.     i = Math.clamp(0, Infinity, i - 1)
  41. basic.showNumber(i)
  42.     while (true) {
  43.         wait(delta_time)
  44.         timepassed2 += delta_time
  45.         console.log(timepassed2)
  46. if (timepassed2 >= cooldown) {
  47.             break;
  48.         }
  49.     }
  50.     timepassed2 = 0
  51.     iscooldown = false
  52. })
  53. let last_value = 0
  54. let n = 0
  55. let cooldown = 0
  56. let iscooldown = false
  57. let music_data: number[] = []
  58. let delta_time = 0
  59. let timepassed = 0
  60. let timepassed2 = 0
  61. let i = 0
  62. delta_time = 0.016
  63. basic.showNumber(i)
  64. // 330 = E | 294 = D | 262 = C
  65. music_data = [
  66. 330,
  67. 294,
  68. 262,
  69. 294,
  70. 330,
  71. 330,
  72. 330,
  73. 294,
  74. 294,
  75. 294,
  76. 330,
  77. 330,
  78. 330,
  79. 294,
  80. 262,
  81. 294,
  82. 330,
  83. 330,
  84. 330,
  85. 294,
  86. 294,
  87. 330,
  88. 294,
  89. 262
  90. ]
  91.  
Advertisement
Add Comment
Please, Sign In to add comment