BorisBuilds
Published © CC BY

Calliope Mini als Wahlcomputer

Wie funktionieren Wahlcomputer? Schüler lernen etwas über Funktionsweise aber auch Vorteile und Nachteile von Wahlcomputern.

IntermediateWork in progress1 hour561
Calliope Mini als Wahlcomputer

Things used in this project

Hardware components

Calliope mini
Calliope mini
×1

Story

Read more

Schematics

PXT Programm

Dies ist ein Bildschirmfoto des Programms im PXT Editor. Um das Programm zu laden, kopiere den Code auf dieser Seite und füge ihn im PXT Editor ( http://pxt.calliope.cc) ein. Wähle hierzu den JavaScript Modus.

Code

Wahlcomputer

Typescript
Dieses Programm wurde mit http://pxt.calliope.cc erstellt. Um es zu benutzen, wähle im Editor "JavaScript" und kopiere den Code hinein.

Verwendung
Das Programm bietet 5 Entscheidungsmöglichkeiten 1-5 zwischen denen die Teilnehmer wählen können.Ein Calliope Mini übernimmt die Rolle des Hauptrechners. Alle anderen können zur Stimmabgabe genutzt werden. Beide Calliopes benutzen dasselbe Programm.

Den Hauptrechner bestimmen
Der Wahlrechner wird bestimmt, indem man nach dem Start die Knöpfe A+B gemeinsam drückt. Das Symbol einer Wahlurne wird angezeigt.

Die Stimmabgabe
Die Teilnehmer an der Wahl wählen ihre Entscheidungsmöglichkeit aus, indem sie mit A oder B eine der Zahlen 1-5 auswählen. Um die Auswahl an den Wahlcomputer zu senden, werden A+B gemeinsam gedrückt. Ein Häckchen wird angezeigt, wenn die Auswahl gesendet wurde. Der Wahlcomputer zeigt bei abgegebener Stimme einen Briefumschlag an.

Beenden der Abstimmung
Ist die Wahl beendet, wird auf dem Wahlcomputer erneut A+B gemeinsam gedrückt. Es wird nun angezeigt, welche Wahlmöglichkeit die Wahl gewonnen hat.
let anzahl_option5 = 0
let anzahl_option4 = 0
let anzahl_option3 = 0
let anzahl_option2 = 0
let anzahl_option1 = 0
let maximalwert = 0
let ist_hauptrechner = false
let gewaehlte_option = 0
let gewinner = 0

radio.onDataPacketReceived(({receivedNumber}) => {
    if (ist_hauptrechner) {
        basic.showLeds(`
            . . . . .
            . . . . .
            . . . . .
            . . . . .
            . . . . .
            `)
        if (receivedNumber == 1) {
            anzahl_option1 = anzahl_option1 + 1
        }
        if (receivedNumber == 2) {
            anzahl_option2 = anzahl_option2 + 1
        }
        if (receivedNumber == 3) {
            anzahl_option3 = anzahl_option3 + 1
        }
        if (receivedNumber == 4) {
            anzahl_option4 = anzahl_option4 + 1
        }
        if (receivedNumber == 5) {
            anzahl_option5 = anzahl_option5 + 1
        }
        basic.showLeds(`
            # # # # #
            # # . # #
            # . # . #
            # . . . #
            # # # # #
            `)
    }
})

// Nächste Option auswählen
input.onButtonPressed(Button.A, () => {
    if(gewaehlte_option = 5){
      gewaehlte_option = 0;
    }
    gewaehlte_option = gewaehlte_option + 1
    basic.showNumber(gewaehlte_option)
})

// Vorherige Option auswählen
input.onButtonPressed(Button.B, () => {
    if(gewaehlte_option = 1){
      gewaehlte_option = 6;
    }
    gewaehlte_option = gewaehlte_option - 1
    basic.showNumber(gewaehlte_option)
})

// Auswahl: Zum Hauptcomputer machen / Auswahl senden / Ergebnis anzeigen
input.onButtonPressed(Button.AB, () => {
    if (!(ist_hauptrechner)) {
        // Es wurde eine Option ausgewählt. Sende sie an den Hauptrechner.
        if (gewaehlte_option != 0) {
            radio.sendNumber(gewaehlte_option)
            basic.showLeds(`
                . . . . #
                . . . # #
                # . # # .
                # # # . .
                . # . . .
                `)
        } else {
            // Es wurde keine whaloption ausgewählt, mache diesen Calliope Mini zum Hauptrechner
            ist_hauptrechner = true
            basic.showLeds(`
                # # . # #
                # . . . #
                # . . . #
                # . . . #
                . # # # .
                `)
        }
    } else {
        // Dies ist der Hauptrechner und A+B wurden erneut gedrückt
        // Starte die Auswertung
        gewinner = 1
        maximalwert = anzahl_option1
        
        if (anzahl_option2 > maximalwert) {
            gewinner = 2
            maximalwert = anzahl_option2
        }
        if (anzahl_option3 > maximalwert) {
            gewinner = 3
            maximalwert = anzahl_option3
        }
        if (anzahl_option4 > maximalwert) {
            gewinner = 4
            maximalwert = anzahl_option4
        }
        if (anzahl_option5 > maximalwert) {
            gewinner = 5
            maximalwert = anzahl_option5
        }
        basic.showString("Gewinner:")
        basic.showNumber(gewinner)
    }
})

//Startaniomation
for (let i = 0; i <= 2 - 1; i++) {
    basic.showString("Wahlcomputer. Drücke A oder B zur Auswahl, dann A+B zum Senden. A+B ohne Auswahl macht den Calliope zum Hauptcomputer.")
}

Credits

BorisBuilds

BorisBuilds

10 projects • 12 followers
IoT professional. Working in IIoT and industry 4.0. Supporting Girls'Day, Jugend Hackt, Open Knowledge Foundation, Code for Hamburg and more

Comments