Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Your first Sniff program

Learning Sniff is easy - learn Scratch! Get good at Scratch. When you do, you'll find you reach a point where Scratch is slowing you down. You know what you want to do, but building it in Scratch is tedious. Now you're ready for Sniff.

To write Sniff, just write down what you would make in Scratch:

when start
.say "hello"

The "when green flag" becomes "when start" because there's no mouse to click with. You compile and run that in the terminal, and it prints out the "hello" message.

when start
.forever
..say "hello"
..wait 5 secs

We use the dots on the left hand side to indicate that everything is inside the when block, and the "say" and "Wait" blocks are inside the "forever" block. It's just like Scratch, but we write it, rather than dragging and dropping.

Just like in Scratch, to do more complex things we need variables, which we create using "make"

make x number

when start

.set x to 1
.forever
..say [ x ]
..change x by 1
..wait 1 secs

Sniff is designed to run efficiently on small systems like the Arduino, so one thing that's changed is that variables now have a "type". When we make the variable x we specify that its a number. Other than that, everything works just like Scratch.

To control simple hardware we just declare a digital input or output:

make led digital output 13

when start
.forever
..set led to on
..wait 1 secs
..set led to off
..wait 1 secs

The same code will work on Arduino or Raspberry Pi - on the Pi just change the pin from 13 to 17 and you can flash an LED on or off!

There are lots of examples in the downloads bundle, or you can check through the documentation including the manual, which has a tutorial and language reference.

1 comment: