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.

Wednesday, 5 March 2014

Coffee Break

We're hard at work on the Beta 4 release, which is looking like its going to focus on the Pi: it should detect if you have wiringPi installed, and use it to access the GPIO port. SPI, and I2C should be working, so devices like the RFID reader, and the Wii NunChuck should work on Pi just as well as they do on Arduino.

However I couldn't resist a quick physics experiment. Plug in the tft shield, and add a ds18 temperature sensor on pin A5 (the only one that shield leaves free!), and we an plot a graph of my coffee cooling!

Here's the code:

make ds18 device A5
make temperature number

make tft device
make tftX number
make tftY number
make tftColor number
make message string

when start
.set tftColor to 777
.tell tft to "clear"
.set tftColor to 700
.set tftX to 20
.set tftY to 100*3+20
.tell tft to "move"
.set tftY to 0*3+20
.tell tft to "draw"
.set tftX to 220
.tell tft to "draw"
.broadcast startMeasuring
.broadcast startDrawing

when startMeasuring
.forever
..tell ds18 to "start"
..wait 1 secs
..tell ds18 to "read"
..#say [ temperature ]
..set tftY to (temperature-40)*12+10


when startDrawing
.forever
..wait 1 secs
..set tftX to 0.25*timer+20

..tell tft to "setPixel"

Drawing the axis is the hardest part...

And here's the result:

It works! And we get something that's the beginnings of an asymptotic curve. If I'd left it longer it would have looked better, but then my coffee would be cold...

1 comment:

  1. This code now works on Raspberry Pi too using the built in screen instead of the tft. Updated code for both Pi and Arduino are included in the examples folder of the Sniff Beta 4 download

    ReplyDelete