Permalink
Browse files

Add a couple of Tcl examples: a Tcl version of Gordon's test2.c and f…

…or playing with leds
  • Loading branch information...
1 parent 9775813 commit e215d05866bd7ee57a9e176be3d539f2a02abce6 davidb24v committed Jul 29, 2012
Showing with 67 additions and 0 deletions.
  1. +44 −0 examples/led
  2. +23 −0 examples/test2
View
@@ -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
View
@@ -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.