Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a couple of Tcl examples: a Tcl version of Gordon's test2.c and f…
…or playing with leds
- Loading branch information
davidb24v
committed
Jul 29, 2012
1 parent
9775813
commit e215d05
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
# Restart using Tcl\ | ||
exec tclsh "$0" "$@" | ||
|
||
package require wiringpi | ||
|
||
wiringPiSetup | ||
|
||
# Define pins for some LEDs | ||
set RED {0 1 2} | ||
set YELLOW {3 4 5} | ||
set GREEN {6 7 8} | ||
set ALL [concat $RED $YELLOW $GREEN] | ||
set NLEDS [llength $ALL] | ||
|
||
# All pins are for output | ||
mode $ALL $OUTPUT | ||
|
||
# Pick a delay... | ||
set DELAY 250 | ||
|
||
# switch on | ||
on $RED | ||
delay $DELAY | ||
on $YELLOW | ||
delay $DELAY | ||
on $GREEN | ||
delay $DELAY | ||
|
||
# Now randomly turn LEDs on and off | ||
off $ALL | ||
set delay 25 | ||
for {set rpt 0} {$rpt < 250} {incr rpt} { | ||
set led [expr {int(rand()*$NLEDS+0.5)}] | ||
on $led | ||
delay $delay | ||
off $led | ||
delay $delay | ||
} | ||
|
||
|
||
delay $DELAY | ||
off $ALL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# Restart using Tcl\ | ||
exec tclsh "$0" "$@" | ||
|
||
package require wiringpi | ||
|
||
wiringPiSetup | ||
|
||
pinMode 1 $PWM_OUTPUT | ||
|
||
while { 1 } { | ||
|
||
for {set bright 0} {$bright < 1024} {incr bright} { | ||
pwmWrite 1 $bright | ||
delay 1 | ||
} | ||
|
||
for {set bright 1023} {$bright >= 0} {incr bright -1} { | ||
pwmWrite 1 $bright | ||
delay 1 | ||
} | ||
} |