Wearables Lösung: Unterschied zwischen den Versionen

Aus microbit - Das Schulbuch
Wechseln zu: Navigation, Suche
(Detailschritte)
(Detailschritte)
Zeile 18: Zeile 18:
 
</pre>
 
</pre>
  
* Anzeige bei "wahr" - steht für Kopf
+
* Wenn Knopf A gedrückt wird, beginnt der LED-Streifen zu leuchten
* Anzeige bei "falsch" - steht für Zahl
 
* Anzahl muss mitgezählt werden
 
 
<pre id="01">
 
<pre id="01">
let anzahl_kopf = 0
+
input.onButtonPressed(Button.A, function () {
let anzahl_zahl = 0
+
     strip.showRainbow(1, 360)
input.onGesture(Gesture.Shake, function () {
+
     strip.show()
     if (Math.randomBoolean()) {
 
        anzahl_kopf += 1
 
        basic.showLeds(`
 
            . # . . #
 
            . # . # .
 
            . # # . .
 
            . # . # .
 
            . # . . #
 
            `)
 
     } else {
 
        anzahl_zahl += 1
 
        basic.showLeds(`
 
            . # # # #
 
            . . . . #
 
            . . # # .
 
            . # . . .
 
            . # # # #
 
            `)
 
    }
 
 
})
 
})
 
</pre>
 
</pre>
  
* Anzahl wird jeweils ausgegeben
+
* Wenn Knopf B gedrückt wird, werden die LEDs abgeschaltet
 
 
 
<pre id="01">
 
<pre id="01">
input.onButtonPressed(Button.A, function () {
 
    basic.showNumber(anzahl_kopf)
 
})
 
input.onButtonPressed(Button.AB, function () {
 
    basic.showNumber(anzahl_kopf + anzahl_zahl)
 
})
 
 
input.onButtonPressed(Button.B, function () {
 
input.onButtonPressed(Button.B, function () {
     basic.showNumber(anzahl_zahl)
+
     strip.clear()
 +
    strip.show()
 
})
 
})
 
</pre>
 
</pre>
 
+
>
* Nicht vergessen - Variablen auf 0 stellen
 
 
 
<pre id="01">
 
let anzahl_kopf = 0
 
let anzahl_zahl = 0
 
</pre>
 
  
  

Version vom 28. Dezember 2021, 13:30 Uhr

Hilfestellung

  • Für die Kopf-Seite der Münze kann der Wert "wahr" oder "falsch" genommen werden.
  • Annahme: Kopf entspricht "wahr", Zahl entspricht "falsch"

Detailschritte

  • Beim Start muss die Länge (=Anzahl der LEDs) und der PIN angegeben werden.
  • TIPP: Das Herabsetzen der Helligkeit spart Strom.
Beim Start
let strip: neopixel.Strip = null
basic.showIcon(IconNames.SmallHeart)
strip = neopixel.create(DigitalPin.P0, 60, NeoPixelMode.RGB)
strip.setBrightness(50)
  • Wenn Knopf A gedrückt wird, beginnt der LED-Streifen zu leuchten
input.onButtonPressed(Button.A, function () {
    strip.showRainbow(1, 360)
    strip.show()
})
  • Wenn Knopf B gedrückt wird, werden die LEDs abgeschaltet
input.onButtonPressed(Button.B, function () {
    strip.clear()
    strip.show()
})

>



Zurück zur Aufgabe