This is the initial project plan developed with my son. Since I speak German with him, it's written in German.
- Was moechtest do machen: Blau blinken
- Was bedeutet das genau:
- alle Lampen sind blau
- warte einen Augenblick
- alle Lampen sind aus
- warte einen Augenblick
- fange wieder bei 1 an
loop :infinite do
lamp blue, repeat: 96
sleep 1_000
lamp off, repeat: 96
sleep 1_000
end
- Welche Funktionsbloecke haben wir?
- Schleife (loop)
- Farbe definieren (blau, aus (=schwarz))
- Pause (sleep)
- Wie definieren wir eine Farbe?
- Mit Namen (blau, kek, blue)
- Mit Hex-Zahlen (0x0000FF)
- Mit RGB Werten (0, 0, 255) (Werte im Interval zwischen [0, 255])
- 255 ist maximaler Wert ==> 300 gibt einen Fehler
- Wie definiert man mehrere Lampen? (Anzahl Lampen muss bekannt sein)
- Definiere 1 Farbe & wiederhole sie (fuer eine Anzahl an Lampen / auf alle Lampen)
- Definiere mehrer Lampen und wiederhole sie auf alle
- Definiere Anfangs- und Endfarbe und interpoliere dazwischen
- Definiere Farbverlaeufe
- Regenbogenfarben
- Kombination die oberen Moeglichkeiten
loop :infinite do
lamp red, offset: 58
lamp green, offset: 12
sleep 1_000
lamp off, offset: 58
lamp off, offset: 12
sleep 1_000
end
We made a walkthrough with my son to check whether the library contains all the
element that he was looking for, i.e. we have fulfilled the project plan
(Note: in the code examples we don't include the installation of the library or
the use Fledex
)
- Blue blinking. The solution looks a little bit different, we don't use the
the sleep function, but we do this by a) a divisor and b) a case statement
switching on the two "states" when checking the remaineder of the counter by
two.
led_count = 1 divisor = 10 led_strip :one, :kino do animation :blink_blue do triggers -> counter = triggers[:one] || 0 counter = trunc(counter/divisor) case rem(counter, 2) do 0 -> leds(1) |> black |> repeat(led_count) 1 -> leds(1) |> blue |> repeat(led_count) end end end
- see above. We have all the elements (even though in a slightly different form)
- see above. We have all the elements (even though in a slightly different form)
- To define a color we can do the following:
This gives us 10 leds with the first 5 being colored: blue, red, green, blue, red Note1: The last value is outside the range, but will automatically be capped to stay within the allowed range. Hence the last led will be simply red. We won't throw an error. Note2: at this point we do not have translations of the colors (that would be too much work :-) and the customer has started to learn Enlish and therefore it's not a problem anymore
leds(10) |> light(:blue) |> red |> light(0x00ff00) |> light({0, 0, 255}) |> light({500, 0, 0})
- Here the solutions for the different parts:
- Use of the repeat function within the light function (note the offset does need to be specified)
Use of the repeat function for an led sequence (the resulting sequence is shorter compared to the above example):leds(10) |> light(:red, 1, 5)
leds(1) |> light(:red) |> repeat(5)
- But the latter allows us to solve the next one too
leds(3) |> red |> green |> blue |> repeat(3)
- This is easily done with the gradient function
leds(10) |> gradient(:blue, :red)
- This is solved as the above one, but we use the rainbow function
leds(10) |> rainbow
- The above can be combined in a wild way:
l1 = leds(7) |> rainbow |> repeat(3) leds(50) |> light(l1, 5) |> light(l1, 30)
- The offset can be defined by using the offset function as shown in 5.5
The customer has accepted the implementation and we can close down this project plan thereby :-)