|
|
The schemer interface
(introduction
page here)
(some example
programs)
The schemer interface allows you to quickly write and customize programs
from your web browser, and then send those programs to schemer. It
uses visible light directly from your computer screen so you don't need
extra wires or hardware.
|
|
|
Writing programs
Schemer understands short, simple programs written in your web browser.
Generally, most things you will type look like this:
|
|
The procedure name (right) tells schemer to flash the lightboards in
sequence, to the right.
Most procedures need a number which tell
them how fast to do something. 1 is really fast, and 10
takes much longer.
The brackets () group the procedure name and number together.
|
|
|
To fade right then left, you would type:
|
|
To send this program to schemer,
- Go to the schemer
programming page.
- Press the touch pad for 1 second.
The onboard light will flash 3 times, then turn off.
- Put the ambient light sensor in front of the yellow flower.
- Press "Send".
- Hold it still until the web browser finishes sending the program.
If there's a problem, hold it closer to the screen or make the
display brighter. Then try again.
The touch pad measures the resistance in your finger. You might need a wet
finger, or a paper clip to connect the touch pad to minus.
|
Summary of schemer light procedures
| (right 2) | fade lights right |
| (left 2) | fade lights left |
| (in 2) | fade starting from outside
edges, towards the middle |
| (out 2) | fade starting in the
middle, towards
edges |
| (twinkle 2) | randomly light up |
| (center 2) | flash only the center
light |
|
To insert a pause between flashing lights, type
So for example, to insert a pause in the previous program, you would type:
(right 2)
(wait 4)
(left 2)
|
Sometimes, you might want Schemer to change speeds automatically. To do so,
use the (sensor) name, which gives Schemer a
different number depending on if a room is bright or dark, or if the
temperature is hot or cold. This way, if you write
instead of (twinkle 2), then it will go really fast if you take it
outside, and go slower in a dim room.
|
These examples so far would run only once. When schemer finishes evaluating
these procedures, it waits for you to send new programs, or to press the
touchpad to rerun the program.
There two ways to make schemer repeat things. The first looks like this:
(repeat 3
(right 2)
(wait 4)
(left 2)
(wait 4)
)
Notice how the brackets group the procedures? The first thing after the word
repeat is a number, and the next things are all the procedures
you want to repeat.
|
You can also repeat repeats, like this:
(repeat 2
(left 2)
(repeat 4
(twinkle 1)
(in 1)
(out 1)
)
(wait 3)
)
You could certainly write it all on one line, but the first way can be
easier to read.
(repeat 2 (left 2) (repeat 4 (twinkle 1) (in 1) (out 1)) (wait 3) )
|
The second way of repeating things involves defining your own procedure that
then calls itself, like this:
(define (pattern)
(right 2)
(left 2)
(wait 2)
(pattern)
)
In other words:
To repeat a pattern, do these things and then,
call the pattern again
(define (pattern) (right 2) (left 2) (wait 2)
(pattern))
You could also define another procedure, the important thing is that the
name being defined, and the name being called are the same:
(define (my-special-name-for-this-procedure)
(twinkle 3)
(in 3)
(out 2)
(my-special-name-for-this-procedure)
)
|
Now that you've defined the procedure, you need to tell schemer to call it.
Remember, even when a procedure was already defined - for example
(twinkle 3), you still needed to call it by typing its name. The
(define) statement just tells schemer that there is a group of
precedures held together by that name.
To define and run your endlessly repeating pattern, you would therefore need
to write this:
(define (pattern)
(right 2)
(left 2)
(wait 2)
(pattern)
)
(pattern)
That last (pattern) is the one that tells schemer to run the
procedure that was defined.
|
More examples coming soon!
|
|
All schemer procedures:
| (right 2) | fade lights right |
| (left 2) | fade lights left |
| (in 2) | fade starting from outside
edges, towards the middle |
| (out 2) | fade starting in the
middle, towards
edges |
| (twinkle 2) | randomly light up |
| (center 2) | flash only the center
light |
| |
| |
| The next three procedures tell Schemer how to change
the lights when you do the 6 light procedures above: |
| (fade) | Fade the lights one by one. |
| (build) | Leave lights on, so at the
end all five lights are lit.
|
| (countdown) | Start with all lights on,
and one by one, turn them off. |
| |
| |
| (wait 2) |
Wait some time before doing the next procedure
|
| (sleep 2) |
Tell schemer to sleep after 2 minutes have passed |
| |
| (repeat 3 (right 2)) |
Repeat the (right) procedure three times.
|
| |
| |
| Using (sensor), Schemer automatically
changes speeds or number of repetitions depending on the level of brightness. |
(twinkle (sensor))
|
Use (sensor) instead of a number like 2, to
change speeds automatically.
|
(repeat (sensor) (twinkle 2))
|
The number of repetitions can be 1, 2, 3 or 4 depending on sensor levels.
|
| |
| |
| |
n
| Use the number contained in n to
a procedure. For example, within a define statement, you could write
(twinkle n) instead of (twinkle 2)
|
| (+1 n) | Use a number 1 greater
than n: (twinkle (+1 n)) |
| (-1 n) | Use a number 1 less
than n: (twinkle (-1 n)) |
Please note: The following advanced procedures are not fully
functional in schemer yet. |
| (if switch (left 2) (twinkle 2) ) | Fade left if switch is pressed, or do twinkle if it isn't.
|
(if switch ((left 2) (right 2)) (twinkle 2) ) | Fade left and right if switch is pressed, or do twinkle if it isn't.
Notice the double brackets that group multiple procedures.
|
| |
| (if (even? n) (left 2) (right 2)) | |
| (if (odd? n) (left 2) (right 2)) | |
| (if (= n 2) (left 2) (right 2)) | |
| (if (!= n 2) (left 2) (right 2)) | |
| (if (> n 2) (left 2) (right 2)) | |
| (if (< n 2) (left 2) (right 2)) | |
| |
| |
(define (a-name)
(repeat 3 (left 2) (right 2)) ) |
Create a new procedure called a-name that will
repeat the (left) (right) patterns three times. |
|
|
Some example programs:
| |
(repeat 4
(repeat 2
(left 1)
(right 1))
(center 2))
|
Flash left and right fast twice, then twinkle once. Repeat
the whole thing 4 times before turning off.
|
| |
| |
| |
(define (slower n)
(repeat 3 (left n) (right n))
(slower (+1 n)) )
(slower 0) |
Create a new procedure called slower that
takes a number n so that each time it calls itself, the lights
become slower and slower. |
| |
| |
| |
(define (alternate n)
(if (even? n) (left 1) (right 1)
(alternate (+1 n)) )
(alternate 0) |
Create a new procedure called alternate that
takes a number n so that it fades left if the number is even, or
right ig the number is odd. |
|