Tino Hempel
Published © CC BY-NC-SA

Micro:Bit Binäruhr mit RTC - micro:bit binary clock with RTC

Mithilfe des RTC-Moduls wird der BBC Microbit zur Binäruhr. Es können Wochentag, Uhrzeit, Tag, Monat und Jahr angezeigt/eingestellt werden.

IntermediateShowcase (no instructions)2 hours180
Micro:Bit Binäruhr mit RTC - micro:bit binary clock with RTC

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
incl. Batteriehalter
×1
Edge Connector Breakout Board for the BBC micro:bit
×1
Tiny RTC DS1307
Unbedingt den Hinweis https://www.amazon.de/review/R3ETNW0EEPACPW/ref=cm_cr_srp_d_rdp_perm?ie=UTF8&ASIN=B00CWX6UXY beachten!
×1
Jumper wires (generic)
Jumper wires (generic)
×5

Software apps and online services

MakeCode
Microsoft MakeCode
pxt.microbit.org
micro:bit pxt.microbit.org

Story

Read more

Custom parts and enclosures

HEX-File

Schematics

Blockly

Schaltung

Code

Quelltext

Typescript
let wert = 0
let r = 0
let bcd = 0
let y = 0
let list_RTC: number[] = []
let item = 0
let takt = 0
let merkerA = 0
let index = 0
function anzeigen2()  {
    basic.clearScreen()
    for (let index2 = 0; index2 <= 2; index2++) {
        item = list_RTC[index2 + 4]
        y = 1
        while (item > 0) {
            r = item % 2
            item = (item - r) / 2
            if (r == 1) {
                led.plot(index2 * 2, 5 - y)
            }
            y += 1
        }
    }
}
function anzeigen()  {
    for (let index3 = 0; index3 <= 4; index3++) {
        led.unplot(0, index3)
        led.unplot(1, index3)
        led.unplot(2, index3)
        led.unplot(4, index3)
    }
    led.unplot(3, 4)
    for (let index4 = 0; index4 <= 2; index4++) {
        item = list_RTC[index4 + 1]
        y = 1
        if (index4 == 0) {
            if (item >= 32) {
                led.plot(3, 4)
                item += -32
            }
        }
        while (item > 0) {
            r = item % 2
            item = (item - r) / 2
            if (r == 1) {
                if (index4 == 0) {
                    led.plot(4, 5 - y)
                } else {
                    led.plot(2 - index4, 5 - y)
                }
            }
            y += 1
        }
    }
}
input.onButtonPressed(Button.A, () => {
    if (merkerA == 0) {
        merkerA = 1
    }
})
index = 0
takt = 1
list_RTC = [0, 0, 0, 0, 0, 0, 0, 0]
pins.i2cWriteNumber(
104,
0,
NumberFormat.UInt8LE,
false
)
bcd = pins.i2cReadNumber(104, NumberFormat.UInt8LE, false)
// alternativ:
//
// einer = bcd & 0x0F
//
// zehner = bcd >> 4
//
wert = (bcd - bcd % 16) / 16 * 10 + bcd % 16
pins.i2cWriteNumber(
104,
wert,
NumberFormat.UInt16BE,
false
)
pins.i2cWriteNumber(
104,
7 * 256 + 144,
NumberFormat.UInt16BE,
false
)
for (let index5 = 0; index5 <= 6; index5++) {
    pins.i2cWriteNumber(
    104,
    index5,
    NumberFormat.UInt8LE,
    false
    )
    bcd = pins.i2cReadNumber(104, NumberFormat.UInt8LE, false)
    // alternativ:
    //
    // einer = bcd & 0x0F
    //
    // zehner = bcd >> 4
    //
    wert = (bcd - bcd % 16) / 16 * 10 + bcd % 16
    list_RTC[index5] = wert
}
basic.forever(() => {
    if (merkerA != 0) {
        list_RTC[0] = 0
        basic.clearScreen()
        for (let index6 = 0; index6 <= 5; index6++) {
            if (index6 < 3) {
                anzeigen()
                led.plot(2, index6)
            } else {
                basic.clearScreen()
                anzeigen2()
                led.plot(1, index6 - 3)
            }
            while (merkerA == index6 + 1) {
                if (input.buttonIsPressed(Button.B)) {
                    wert = list_RTC[index6 + 1]
                    wert += 1
                    if (index6 == 0) {
                        if (wert == 60) {
                            wert = 0
                        }
                    } else if (index6 == 1) {
                        if (wert == 24) {
                            wert = 0
                        }
                    } else if (index6 == 2) {
                        if (wert == 8) {
                            wert = 1
                        }
                    } else if (index6 == 3) {
                        if (wert == 32) {
                            wert = 1
                        }
                    } else if (index6 == 4) {
                        if (wert == 13) {
                            wert = 1
                        }
                    } else if (index6 == 5) {
                        if (wert == 32) {
                            wert = 0
                        }
                    }
                    list_RTC[index6 + 1] = wert
                    if (index6 < 3) {
                        anzeigen()
                        led.plot(2, index6)
                    } else {
                        anzeigen2()
                        led.plot(1, index6 - 3)
                    }
                    basic.pause(500)
                } else if (input.buttonIsPressed(Button.A)) {
                    merkerA += 1
                    basic.pause(500)
                    if (index6 < 3) {
                        led.unplot(2, index6)
                    } else {
                        led.unplot(1, index6 - 3)
                    }
                }
            }
        }
        for (let index7 = 0; index7 <= 6; index7++) {
            wert = list_RTC[index7]
            bcd = (wert - wert % 10) / 10 * 16 + wert % 10
            bcd += index7 * 256
            pins.i2cWriteNumber(
            104,
            bcd,
            NumberFormat.UInt16BE,
            false
            )
        }
        merkerA = 0
        basic.clearScreen()
    } else {
        while (input.buttonIsPressed(Button.B)) {
            anzeigen2()
            basic.pause(100)
        }
        anzeigen()
        while (takt == 1) {
            led.plot(2, 1)
            led.plot(2, 3)
            if (pins.analogReadPin(AnalogPin.P1) < 512) {
                takt = 0
            }
        }
        for (let index8 = 0; index8 <= 6; index8++) {
            pins.i2cWriteNumber(
            104,
            index8,
            NumberFormat.UInt8LE,
            false
            )
            bcd = pins.i2cReadNumber(104, NumberFormat.UInt8LE, false)
            // alternativ:
            //
            // einer = bcd & 0x0F
            //
            // zehner = bcd >> 4
            //
            wert = (bcd - bcd % 16) / 16 * 10 + bcd % 16
            list_RTC[index8] = wert
        }
        while (takt == 0) {
            led.unplot(2, 1)
            led.unplot(2, 3)
            if (pins.analogReadPin(AnalogPin.P1) > 512) {
                takt = 1
            }
        }
    }
})

Credits

Tino Hempel

Tino Hempel

12 projects • 6 followers

Comments