Close

A dice with LabDroid

A project log for LabDroid

Happy Prototyping powered by Android

HerrHerklotzHerrHerklotz 06/30/2020 at 21:170 Comments

Today I did a simple dice with LabDroid:

function getRandom(max) {
  return 1+Math.floor(Math.random() * Math.floor(max))
}

let force = 0.0
let rolled = ""

while(true) {
    const accel = $in(0)
    
    force += Math.abs(accel.x) + Math.abs(accel.y)
    
    if (force > 100.0) // Keep the dice on the floor
        force = 90.0
    else if (force > 30.0) {
        force *= 0.6
        rolled += getRandom(6) + " "
    }
    else if (force > 10) // The dice wiggles out
        force *= 0.6 
    else {
        if (rolled.length > 0) {
            $log(rolled + "*" + getRandom(6) + "*")
            rolled = ""
            $sleep(1000) // Give the dice some time to cool down
        }
        
        force = 0.0
    }
}
And the output:

Still thinking about how I could share some example projects. Hackaday, Instructable, YouTube or Github?! :/

Any other recommendations? :D

Discussions