Skip to content

Commit

Permalink
Add a couple of Tcl examples: a Tcl version of Gordon's test2.c and f…
Browse files Browse the repository at this point in the history
…or playing with leds
  • Loading branch information
davidb24v committed Jul 29, 2012
1 parent 9775813 commit e215d05
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/led
@@ -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
23 changes: 23 additions & 0 deletions examples/test2
@@ -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
}
}

0 comments on commit e215d05

Please sign in to comment.