I’m a bit ‘old-school’ as I started teaching computer programming, or coding, in 1968 and I like DOCUMENTATION. I do not want to guess or try this to see if it will work if the guy I bought a device from hasn’t told me how to use it properly. I know that developing software takes time but documenting it is should be part of the package. As examples of good practice I suggest you look at the work of Alex Eames of Raspi.tv and his documentation for Raspio-duino
http://rasp.io/wp-content/uploads/2015/04/raspio-duino.pdf
or ProHAT
http://rasp.io/wp-content/uploads/2016/04/Pro-Hat-GPIO-Zero.pdf
and Ben Nuttall’s gpiozero
http://gpiozero.readthedocs.io/en/v1.3.1/
I got a Mega Treasure Chest via Kickstarter. I was disappointed with the early versions of the software and gave up on it over the summer. Now that an improved version of the software is available and the nights are drawing in I’ve been giving it another try. Search as I might I still cannot find any useful documentation for ‘flotilla-python’ . There are a few examples, using some of the simplest commands, for the least complicated inputs and outputs but not enough details.
While we wait for the ‘official documentation’ I thought that I would post a few examples of what I have found out and hope that others will join in and add to the published body of knowledge. Unless teachers, who have little time, can easily access this information they will not be able to use Flotilla effectively in secondary schools. Its great physical kit, now working much better, so let’s pool what we have worked out so far.
My first contribution uses Touch, Rainbow, Dial and Number. Before you start using flotilla-python you must remember to turn off the flotilla service for Rockpool with the command ‘sudo service flotilla stop’ in terminal.
The script changes colours on the Rainbow, displays values on Number, inputs values from Dial and carries out a few simple calculations.
rainbow.set_pixel(pixel, r ,g, b).update()
pixel ( range: 0 to 4)
r, g, b (range: 0 to 255) colour mixing values
.update() this displays the changes immediately rather than with rainbow.update() later.
number.set_number(n)
n is an integer (range: 0 to 9999)
number.update() displays the changed value (often forgotten)
dial.data[0]
This reads the value from Dial (range: 0 to 1023) but returns a string. It must be converted to a number before you can carry out calculations or pass it on to Number. Use int(dial.data[0]) to convert to integer and float(dial.data[0]) for floating point.
#!/usr/bin/env python3
#Touch Rainbow Dial Number
# Tony Goodhew 18 Oct 2016
import flotilla
import time
client = flotilla.Client(
requires={
'three':flotilla.Touch,
'four':flotilla.Dial,
'seven':flotilla.Rainbow,
'eight':flotilla.Number
})
touch = client.first(flotilla.Touch)
dial = client.first(flotilla.Dial)
rainbow = client.first(flotilla.Rainbow)
number = client.first(flotilla.Number)
number.clear().update()
print("Touch the buttons and turn the dial\n")
print(" Use CTRL-C to stop")
try:
while True:
if touch.one:
rainbow.set_pixel(0,128,0,0).update() #red
number.set_number(1111)
if touch.two:
rainbow.set_pixel(0,0,128,0).update() #green
number.set_number(2222)
if touch.three:
rainbow.set_pixel(0,0,0,128).update() #blue
dial_val = int(dial.data[0]) #Read dial and change string to integer
number.set_number(dial_val)
if touch.four:
rainbow.set_pixel(0,100,0,100).update() #magenta
dial_val = float(dial.data[0]) # Changed to FP: range 0 to 1023
percentage = int(dial_val * 1000.0 / 1023.0 / 10.0)
number.set_number(percentage)
number.update()
time.sleep(0.2)
except KeyboardInterrupt:
number.clear().update()
client.stop()
print("\nStopped with CTRL-C")
In an editor, like idle3, if you type a module name and full stop then press tab you get a list of possible commands. For example, “dial. “ gives the following list:
channel, channel_index, clamp, client, data, is_a, name, position, send, set_data, stop.
What do they do? Which are possibly dangerous?
I would like to take control of the LEDS on Touch to show which one was last pressed. Can anyone help?