Skip to content

Commit

Permalink
treehouses led sandstorm (fixes #2036) (#2039)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
rjpadilla and dogi authored Feb 25, 2021
1 parent 4f0cd86 commit 9cea743
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ led [green|red] [mode] sets the led mode
[lantern|stpatricks|easter|labourday]
[eid|dragonboat|independenceday|onam]
[diwali|thanksgiving|christmas]
[heavymetal|dance|kecak|random]
[heavymetal|dance|kecak|sandstorm]
[random]
power [mode|current|freq|status] sets the power mode or check power mode/CPU frequency
uptime [boot|start|stop|log] displays uptime and boot time of the Raspberry Pi
rtc <on|off> [rasclock|ds3231] sets up the rtc clock specified
Expand Down
2 changes: 2 additions & 0 deletions _treehouses
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ treehouses inspire random
treehouses internet
treehouses internet reverse
treehouses led
treehouses led blackhistorymonth
treehouses led carnival
treehouses led christmas
treehouses led dance
Expand Down Expand Up @@ -197,6 +198,7 @@ treehouses led red kbd-
treehouses led red none
treehouses led red oneshot
treehouses led red timer
treehouses led sandstorm
treehouses led thanksgiving
treehouses led valentine
treehouses led heavymetal
Expand Down
3 changes: 2 additions & 1 deletion modules/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ led [green|red] [mode] sets the led mode
[lantern|stpatricks|easter|labourday]
[eid|dragonboat|independenceday|onam]
[diwali|thanksgiving|christmas]
[heavymetal|dance|kecak|random]
[heavymetal|dance|kecak|sandstorm]
[random]
power [mode|current|freq|status] sets the power mode or check power mode/CPU frequency
uptime [boot|start|stop|log] displays uptime and boot time of the Raspberry Pi
rtc <on|off> [rasclock|ds3231] sets up the rtc clock specified
Expand Down
105 changes: 104 additions & 1 deletion modules/led.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ function led {
echo "Both LED: on 1 sec; off 1 sec; twice"
kecak > "$LOGFILE"
;;
sandstorm)
checkroot
echo "leds are set to sandstorm mode."
echo "Look at your RPi leds, both leds will be in this pattern..."
echo "Green and Red LED will flash at the beat of Darude - Sandstorm."
echo "This pattern is 25 seconds long..."
echo "Have fun!!"
sandstorm > "$LOGFILE"
;;
random)
checkroot
random
Expand Down Expand Up @@ -815,6 +824,97 @@ function kecak {
led green "$current_green"
}

function sandstorm {
current_green=$(led "green")
current_red=$(led "red")

set_brightness 0 0 && set_brightness 1 0 # green and red off
sleep 0.5

#intro
x=0
while [ $x -le 2 ]; do
for ((i=0;i<6;i++)); do
set_brightness 0 1 && set_brightness 1 0 # green on and red off
sleep 0.125
set_brightness 0 0 && set_brightness 1 1 # green off and red on
sleep 0.125
done
set_brightness 0 1 && set_brightness 1 0 # green on and red off
sleep 1.0
x=$(( x + 1 ))
done

#bridge
x=0
while [ $x -le 3 ]; do
for ((i=0;i<6;i++)); do
set_brightness 0 1 && set_brightness 1 0 # green on and red off
sleep 0.0625
set_brightness 0 0 && set_brightness 1 1 # green off and red on
sleep 0.0625
done
set_brightness 0 1 && set_brightness 1 0 # green on and red off
sleep .15
x=$(( x + 1 ))
done

x=0
while [ $x -le 3 ]; do
for ((i=0;i<5;i++)); do
set_brightness 0 1 && set_brightness 1 0 # green on and red off
sleep 0.03125
set_brightness 0 0 && set_brightness 1 1 # green off and red on
sleep 0.03125
done
set_brightness 0 1 && set_brightness 1 0 # green on and red off
x=$(( x + 1 ))
done

#chorus
x=0
while [ $x -le 2 ]; do
for ((i=0;i<6;i++)); do
set_brightness 0 1 && set_brightness 1 0 # green on and red off
sleep 0.08
set_brightness 0 0 && set_brightness 1 1 # green off and red on
sleep 0.08
done
set_brightness 0 1 && set_brightness 1 0 # green on and red off
sleep .10
x=$(( x + 1 ))
done

x=0
while [ $x -le 1 ]; do
for ((i=0;i<6;i++)); do
set_brightness 0 0 && set_brightness 1 1 # green off and red on
sleep 0.08
set_brightness 0 1 && set_brightness 1 0 # green on and red off
sleep 0.08
done
set_brightness 0 0 && set_brightness 1 1 # green off and red on
sleep .20
x=$(( x + 1 ))
done

x=0
while [ $x -le 3 ]; do
for ((i=0;i<6;i++)); do
set_brightness 0 1 && set_brightness 1 0 # green on and red off
sleep 0.08
set_brightness 0 0 && set_brightness 1 1 # green off and red on
sleep 0.08
done
set_brightness 0 1 && set_brightness 1 0 # green on and red off
sleep .10
x=$(( x + 1 ))
done

led green "$current_green"
led red "$current_red"
}

function random {
echo "selecting from: "
led_help | grep "\[" | cut -d "[" -f2 | cut -d "]" -f1 | sed -n '1!p'| head -2 | sed 's/|/ /g'| sed -e 's/ random//'
Expand All @@ -834,7 +934,7 @@ function led_help {
echo "Usage: $BASENAME led [green|red] [mode]"
echo " $BASENAME led [newyear|blackhistorymonth|lunarnewyear|valentine|carnival|lantern|stpatricks]"
echo " [easter|labourday|eid|dragonboat|independenceday|onam|diwali|thanksgiving]"
echo " [christmas|dance|heavymetal|random]"
echo " [christmas|dance|heavymetal|sandstorm|random]"
echo
echo "Sets or returns the led mode"
echo
Expand Down Expand Up @@ -937,6 +1037,9 @@ function led_help {
echo " $BASENAME led kecak"
echo " This will set the mode of the led to kecak"
echo
echo " $BASENAME led sandstorm"
echo " This will set the mode of the led to sandstorm"
echo
echo " $BASENAME led random"
echo " This will set the mode of the led to one of the above festivities"
echo
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@treehouses/cli",
"version": "1.25.6",
"version": "1.25.7",
"remote": "4000",
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
"main": "cli.sh",
Expand Down
7 changes: 7 additions & 0 deletions tests/led/sandstorm.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!usr/bin/env bats
load ../test-helper

@test "$clinom led sandstorm" {
run "${clicmd}" led sandstorm
assert_success && assert_output -p `heartbeat`
}

0 comments on commit 9cea743

Please sign in to comment.