Ball Rolling Down 5–Metre Ramp

UPDATE: See the following page I created:

Motion Analysis Rolling Down A Ramp

 

 

“https://youtu.be/MwSYBzq7TUw?si=7QVp86mzyXZugM1o”

 

 

Those interested in the code used to run the Micro:Bit, here it is:

let startTime = 0
let elapsed = 0
let lastTime = -1
let state = 0 // 0 READY, 1 TIMING, 2 DONE

pins.setPull(DigitalPin.P0, PinPullMode.PullUp)
pins.setPull(DigitalPin.P1, PinPullMode.PullUp)

function showTimeMs(msTotal: number) {
let s = Math.idiv(msTotal, 1000)
let ms = msTotal % 1000

// pad milliseconds to 3 digits
let msStr = "" + ms
if (ms < 10) {
msStr = "00" + msStr
} else if (ms < 100) {
msStr = "0" + msStr
}

basic.showString("" + s + "." + msStr + "s")
}

basic.showString("READY")

basic.forever(function () {

// START
if (state == 0 && pins.digitalReadPin(DigitalPin.P0) == 0) {
startTime = input.runningTime()
state = 1
basic.showString("GO")
basic.pause(150) // debounce
}

// STOP
if (state == 1 && pins.digitalReadPin(DigitalPin.P1) == 0) {
elapsed = input.runningTime() - startTime
lastTime = elapsed
state = 2
showTimeMs(elapsed)
basic.pause(150) // debounce
}
})

// RESET (Button A)
input.onButtonPressed(Button.A, function () {
state = 0
basic.clearScreen()
basic.showString("READY")
})

// RECALL LAST TIME (Button B)
input.onButtonPressed(Button.B, function () {
basic.clearScreen()
if (lastTime >= 0) {
showTimeMs(lastTime)
} else {
basic.showString("NONE")
}
})

Do let me know if you think the code can be updated.