OmegalandDouglas Kiang
Created October 5, 2016 © CC BY

MicroMultiBitTool

With the MicroMultiBitTool you can have a watch, a step counter, and a compass all in one thing!

BeginnerWork in progress1.5 hours46
MicroMultiBitTool

Things used in this project

Story

Read more

Code

Javascript Code

JavaScript
let Steps = 0
let Point = 0
let Mode = 0
basic.forever(() => {
    Point = input.compassHeading()
    if (0 == Mode) {
        if (Point < 22 || 337 < Point) {
            basic.showLeds(`
                . . # . .
                . # . # .
                . . # . .
                . . # . .
                . . . . .
                `)
        } else if (Point < 67) {
            basic.showLeds(`
                # # # . .
                # . . . .
                # . # . .
                . . . # .
                . . . . .
                `)
        } else if (Point < 112) {
            basic.showLeds(`
                . . . . .
                . # . . .
                # . # # .
                . # . . .
                . . . . .
                `)
        } else if (Point < 157) {
            basic.showLeds(`
                . . . . .
                . . . # .
                # . # . .
                # . . . .
                # # # . .
                `)
        } else if (Point < 202) {
            basic.showLeds(`
                . . . . .
                . . # . .
                . . # . .
                . # . # .
                . . # . .
                `)
        } else if (Point < 247) {
            basic.showLeds(`
                . . . . .
                . # . . .
                . . # . #
                . . . . #
                . . # # #
                `)
        } else if (Point < 292) {
            basic.showLeds(`
                . . . . .
                . . . # .
                . # # . #
                . . . # .
                . . . . .
                `)
        } else if (Point < 337) {
            basic.showLeds(`
                . . # # #
                . . . . #
                . . # . #
                . # . . .
                . . . . .
                `)
        }
    }
})
let Hour = 2
let Min = 0
basic.forever(() => {
    if (60 <= Min) {
        Min = 0
        Hour += 1
    }
    if (12 < Hour) {
        Hour = 1
    }
    if (1 > Hour) {
        Hour = 12
    }
})
basic.forever(() => {
    basic.pause(60000)
    Min += 1
})
basic.forever(() => {
    input.onGesture(Gesture.Shake, () => {
        Steps += 1
    })
    input.onButtonPressed(Button.B, () => {
        Steps = 0
    })
})
basic.forever(() => {
    if (2 == Mode) {
        basic.showNumber(Steps)
    }
})
Mode = 0
basic.forever(() => {
    input.onButtonPressed(Button.A, () => {
        Mode += 1
    })
})
basic.forever(() => {
    if (2 < Mode) {
        Mode = 0
    }
    if (1 == Mode) {
        basic.showNumber(Hour)
        basic.showNumber(Min)
        basic.pause(1000)
    }
})
basic.forever(() => {
    if (1 == Mode) {
        input.onPinPressed(TouchPin.P0, () => {
            Min += 1
        })
        input.onPinPressed(TouchPin.P1, () => {
            Min += 10
        })
        input.onPinPressed(TouchPin.P2, () => {
            Hour += 1
        })
    }
})

Credits

Omegaland

Omegaland

1 project • 0 followers
Douglas Kiang

Douglas Kiang

5 projects • 4 followers
Teacher, dad, reformed skydiver, friend to dogs, food truck aficionado.

Comments