Sparkle programs are actions and numbers grouped with parentheses.       Jump to summary.
 
(always
  (right 2))



There are five unique lights in a Sparkle system, (you can have more than 5, just that some of them will light up together).

In (right 2), right is the command to fade the lights right, and 2 makes the total cycle 2 seconds long.

If you prefer a light to stay on, type:

(on 3)      ; turn on the third light (which is also Sparkle)
(off 3)     ; turn off the third light
(on all)    ; turn on all lights



To change the speed it comes on or goes off, use a second number:

(on 3 5)      ; turn on the middle light slowly, over 5 seconds
(on 5 10)     ; turn on the 5th light even more slowly, over 10 seconds
(on all 10)   ; turn on all lights slowly



The light numbers accepted by the (on ) and (off ) actions are 1 through 5 and the speeds are 1, 2, 5, and 10.




(always
  (if (touched)
    (right 2)))



(always
  (if (touched)
    (on random)))       turn on a random light every time it's touched



; using (multiple) keeps a previous light on ; so each time you touch, more lights come on, until they're all lit
; if you touch again when all are lit, they all turn off again to restart the cycle

(multiple)
(always
  (if (touched)
    (on random)))       turn on a random light every time it's touched



; first turn all lights on, then turn a random one off till they're all off
; if you touch again when all are off, they all turn on again to restart the cycle

(multiple)
(left 1)
(always
  (if (touched)
    (off random)))       turn off a random light every time it's touched



; flash the lights only when the sensor value is greater than 3
; connect the sound sensor to activate with conversation
; connect the motion sensor to activate when you move

(always
  (if (> sensor 3)
    (right 2)))



(always
  (if (touched)
    (right 2)      ; do this if the board is touched
    (left 2)))     ; otherwise do that




(always
  (if (touched)
    ((left 2)(right 2))   ; do these if the board is touched
    ((in 1)(out 2)) )     ; otherwise do these
  (wait 10))



(always
  (if (< sensor 2) (flash 5))
  (if (touched)    (twinkle 2)))




(always
  (twinkle sensor))    ; automatically speed up in a bright room, slow down in the dark




(always
  (repeat 3 (right 2) (left 2))
  (wait 10))



(always
  (repeat sensor (right 2) (left 2))    ; repeat automatically 1-10 times based on sensor level
  (wait 10))



; with multiple mode, turn lights on, one by one, till they are all lit
; then with countdown mode, turn off the lights, one by one

(always
  (multiple) (right 2)
  (wait 10)
  (countdown) (left 2)
  (wait 10))



; turn on the motor, fade left, turn off motor, fade right

(always
  (motor on) (left 5)
  (motor off) (right 5))



; create an attention-getting flash if your design hasn't been touched in 90 seconds
; if you touched it within 90 seconds, flash Sparkle and then reset

(always
  (if (touched)
    (flash 5)
    ((wait 90) (repeat 10 (left 1/2) (right 1/2) ))))



; flash slowly over 5 seconds, wait 30 seconds, twinkle all the lights for about 3 minutes, then turn off.
; the maximum number you can use for repeats is 10 so we have to nest repeats like this
(flash 5)
(wait 30)
(repeat 5 (repeat 10 (repeat 10 (twinkle 1/2))))
(always (wait 1))



; defined procedures can help organize your programs

(define (pulse)
  (flash 1) (wait 1))

(define (heartbeat)
  (repeat 2 (pulse)) (out 2))

(define (racing n)
  (repeat n (left 1/4) (right 1/4)))

(always
  (if (touched)
    (racing sensor)
    ((heartbeat) (wait 30))))


; alternate the direction of a flashing pattern each time you touch

(define (alternate n)
  (if (touched)
    ( (if (even n) (left 1) (right 1))
      (alternate (+1 n)) )
    (alternate n)))

(alternate 1)



In addition to picking colors from the graphical list, you can also tell Colorwell which colors you want by typing:
 
(always
  (color 7))

Where the number 1 - 10 corresponds to the 10 colors in the PANTONE® fashion color report.
 
 
Here's a short program to gradually change between two colors:


 

(speed 5)        ; set the overall transition speed to 5 seconds
(always
  (color 7)      ; turn to the 7th color of the season (sweet lilac® in Spring 2012)
  (wait 30)      ; wait for 30 seconds in the current color
  (color 2)      ; then turn to the 2nd color of the season (tangerine tango® in Spring 2012)
  (wait 30))     

 
It's impossible for these colors to match the actual PANTONE® colors, for one basic reason: mixing colors with LEDs is an additive process where dark tones (like brown) just cannot be reproduced. We try our best, and are finding ways to improve the accuracy.
 
To mix your own colors, type: (mix 4 9 1)
The numbers are the amount of red, green, and blue to add together.




All Sparkle/Colorwell procedures 

Although inspired by Scheme and Logo, Sparkle is not intended to be a reference implementation of either. The language is influenced by our friends at the Lifelong Kindergarten Group and by our experience at the Craft Technology Group.

 
 
 
 
; (right 2) the semicolon is a comment marker, and causes Sparkle to ignore the rest of the line
 
Change the speed of the lights (in seconds):      (right 1/4) (right 1/2) (right 2) (right 90)
These times are approximate and can vary slightly from real time: 
 
(right 2) fade lights right
(left 2) fade lights left
(in 2) fade starting from outer lights, in towards the middle
(out 2) fade starting in the middle, out towards the outer lights
(twinkle 2) randomly light up
(flash 2) flash Sparkle light
 
(single) (right 2) turn on lights one by one
(multiple) (right 2) leave lights on, so at the end all five lights are lit
(countdown) (right 2) start with all lights on, and one by one, turn them off
 
(on 1) turn the leftmost light on, and stay on
(on 3) turn the middle light on, and stay on
(on all) turn on all lights
(on random) turn on a single random light
(off random) turn off a single random light
(off all) turn off all lights
(motor on) turn on the motor
(motor off) turn off the motor
 
(wait 2) wait some time before doing the next procedure
(sleep) put Sparkle to sleep. You'll need to touch it to wake it up again
(repeat 3 (right 2)) repeat the (right) procedure three times. repeat takes a number from 1-10
(always (right 2)) do the (right) procedure nonstop
 
(right sensor) automatically change speeds
(repeat sensor (right 2)) repeat automatically 1-10 times
 
(right random) randomly change speeds
(repeat random (right 2)) repeat randomly from 1-10 times
 
(if (touched) (right 2) ) fade right if the board is touched
 
(if (touched)
  (right 2)
  (left 2))
 
fade right if board is touched,
else fade left if it isn't.
 
(if (touched)
  ((left 2) (right 2))
  (twinkle 2) )
 
fade left and right if board is touched,
do twinkle if it isn't.
 
 
Instead of the (touched) test you can also use (sensor) tests:
 
(if (> sensor 3)  (right 2))
(if (< sensor 3)  (right 2))
(if (= sensor 3)  (right 2))
(if (even sensor) (right 2))
(if (odd  sensor) (right 2))
(if (> sensor random)  (right 2))
 
 
Procedures and variables
 
(define (change-reps n)
   (repeat n (left 2) (right 2)) )
create a new procedure called change-reps that will
repeat the actions n times
(change-reps 1)
(change-reps 6)
run this new change-reps procedure with different numbers to repeat
 
(define (change-speed s)
   (left s) (right s)) )
create a new procedure called change-speed that will
take s seconds to do the various actions
(change-speed 1/2)
(change-speed 60)
run this new change-speed procedure with different seconds for speed
 
 
Within procedures, you can now use these variables
 
n
 
integers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10:     (repeat n) (right 2))
 
(+1 n) a number 1 greater than n:     (repeat (+1 n) (right 2))
(-1 n) a number 1 less than n:          (repeat (-1 n) (right 2))
 
s seconds: 1/4, 1/2, 1, 2, 5, 10, 15, 30, 60, 90:    (right s)
times are approximate and can vary slightly from real time.
 
(+1 s) use seconds 1 step more than s:     (right (+1 s))
(-1 n) use seconds 1 step less than s:       (right (-1 s))
 
 
(if (> s 1/2)(right 2))
(if (< s 60) (right 2))
(if (> n 1)  (right 2))
(if (< n 10) (right 2))
(if (even n) (right 2))
(if (odd  n) (right 2))
 
(if (< sensor random) (right 2))
(if (= n random) (right 2))
 
 
Try other combinations; Sparkle will complain if it doesn't like it.