Tino Hempel
Published © CC BY-NC-SA

Calliope mini als Mega-Würfel

Calliope mini wird zum Mega-Würfel mit mehreren Würfeln und variabler Augenzahl.

BeginnerShowcase (no instructions)1 hour183
Calliope mini als Mega-Würfel

Things used in this project

Hardware components

Calliope mini
Calliope mini
×1

Software apps and online services

Calliope mini Calliope PXT

Story

Read more

Schematics

Calliope als Mega-Würfel

Calliope Grafik im SVG-Format

Calliope HEX-Datei

Code

Calliope als Mega-Würfel

JavaScript
let wurf = 0
let augen = 0
let würfel = 0
// Wenn geschuettelt, wird für jeder Wuerfel geworfen
// und in Abhaengigkeit die Farbe gesetzt
input.onGesture(Gesture.Shake, () => {
    for (let index = 0; index <= würfel - 1; index++) {
        wurf = Math.random(augen - 1 + 1) + 1
        if (index == 0) {
            basic.setLedColor(Colors.Red)
        } else if (index == 1) {
            basic.setLedColor(Colors.Yellow)
        } else {
            basic.setLedColor(Colors.Blue)
        }
        basic.showNumber(wurf)
        basic.pause(1000)
    }
    basic.clearScreen()
    basic.setLedColor(basic.rgbw(
        0,
        0,
        0,
        0
    ))
})
// Augenanzahl wird stets um 1 erhöht, wenn aber zu
// groß, dann wieder auf 1 gesetzt
input.onButtonPressed(Button.B, () => {
    würfel += 1
    if (würfel == 4) {
        würfel = 1
    }
    basic.showString("Wuerfel:" + würfel)
})
// Würfelanzahl wird stets um 1 erhöht, wenn aber zu
// groß, dann wieder auf 2 gesetzt
input.onButtonPressed(Button.A, () => {
    augen += 1
    if (augen == 10) {
        augen = 2
    }
    basic.showString("Augen:" + augen)
})
input.onButtonPressed(Button.AB, () => {
    würfel = 1
    augen = 6
    basic.showString("Wuerfel:" + würfel)
    basic.showString("Augen:" + augen)
})
würfel = 1
augen = 6

Credits

Tino Hempel

Tino Hempel

12 projects • 6 followers

Comments