From 6eed423dd30cf346949eaf2ff6f662027343bf5b Mon Sep 17 00:00:00 2001 From: Wojciech Wilk Date: Mon, 20 Nov 2023 08:46:39 +0100 Subject: [PATCH] added sound when dot reach either end of a board --- main.blocks | 10 +++++++++- main.ts | 8 ++++++++ pxt.json | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/main.blocks b/main.blocks index 0f347ec..07986fa 100644 --- a/main.blocks +++ b/main.blocks @@ -1 +1,9 @@ -xcounterInitialize variables \ No newline at end of file +xcounterSimple code developed with use of chatGPT 3.5 +Tilt board left or right and use A button to check how many times dot touched the edge on left or right side +Initialize variablesxX-coordinate for the center of the board2` + . . . . . + . . . . . + . . # . . + . . . . . + . . . . . + `Display a single red dot in the center of the boardButton.AFunction to display total count when A button is pressedDisplay the total countcounterGesture.TiltLeftFunction to handle dot movement based on tilt0TRUEGT0x0xMove the dot left if not already at the left edge-10x2TRUELTE0x0music.PlaybackMode.UntilDone784BeatFraction.QuartercounterIncrement counter when dot reaches the left edge1Gesture.TiltRightTRUELT0x4xMove the dot right if not already at the right edge10x2TRUEGTE0x4music.PlaybackMode.UntilDone784BeatFraction.QuartercounterIncrement counter when dot reaches the right edge1 \ No newline at end of file diff --git a/main.ts b/main.ts index c127ba1..b04a52f 100644 --- a/main.ts +++ b/main.ts @@ -1,6 +1,8 @@ /** * Simple code developed with use of chatGPT 3.5 + * * Tilt board left or right and use A button to check how many times dot touched the edge on left or right side + * * Initialize variables */ // Function to handle dot movement based on tilt @@ -10,6 +12,9 @@ input.onGesture(Gesture.TiltLeft, function () { x += -1 basic.clearScreen() led.plot(x, 2) + if (x <= 0) { + music.play(music.tonePlayable(784, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone) + } } else { // Increment counter when dot reaches the left edge counter += 1 @@ -21,6 +26,9 @@ input.onGesture(Gesture.TiltRight, function () { x += 1 basic.clearScreen() led.plot(x, 2) + if (x >= 4) { + music.play(music.tonePlayable(784, music.beat(BeatFraction.Quarter)), music.PlaybackMode.UntilDone) + } } else { // Increment counter when dot reaches the right edge counter += 1 diff --git a/pxt.json b/pxt.json index 3a14857..9f1d2ee 100644 --- a/pxt.json +++ b/pxt.json @@ -21,5 +21,5 @@ "supportedTargets": [ "microbit" ], - "preferredEditor": "tsprj" + "preferredEditor": "blocksprj" }