DIY flotilla-python documentation - Raspberry Pi Forums


i’m bit ‘old-school’ started teaching computer programming, or coding, in 1968 , documentation. not want guess or try see if work if guy bought device hasn’t told me how use properly. know developing software takes time documenting should part of package. examples of practice suggest @ work of alex eames of raspi.tv , documentation raspio-duino
http://rasp.io/wp-content/uploads/2015/ ... -duino.pdf
or prohat
http://rasp.io/wp-content/uploads/2016/ ... o-zero.pdf
, ben nuttall’s gpiozero
http://gpiozero.readthedocs.io/en/v1.3.1/

got mega treasure chest via kickstarter. disappointed versions of software , gave on over summer. improved version of software available , nights drawing in i’ve been giving try. search might still cannot find useful documentation ‘flotilla-python’ . there few examples, using of simplest commands, least complicated inputs , outputs not enough details.

while wait ‘official documentation’ thought post few examples of have found out , hope others join in , add published body of knowledge. unless teachers, have little time, can access information not able use flotilla in secondary schools. great physical kit, working better, let’s pool have worked out far.

first contribution uses touch, rainbow, dial , number. before start using flotilla-python must remember turn off flotilla service rockpool command ‘sudo service flotilla stop’ in terminal.

script changes colours on rainbow, displays values on number, inputs values dial , carries out few simple calculations.
rainbow.set_pixel(pixel, r ,g, b).update()
pixel ( range: 0 4)
r, g, b (range: 0 255) colour mixing values
.update() displays changes rather rainbow.update() later.

number.set_number(n)
n integer (range: 0 9999)
number.update() displays changed value (often forgotten)

dial.data[0]
reads value dial (range: 0 1023) returns string. must converted number before can carry out calculations or pass on number. use int(dial.data[0]) convert integer , float(dial.data[0]) floating point.

code: select all

#!/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 buttons , turn dial\n") print("    use ctrl-c 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 , change string 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 fp: range 0 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 ctrl-c")

in editor, idle3, if type module name , full stop press tab list of possible commands. example, “dial. <tab> “ gives following list:
channel, channel_index, clamp, client, data, is_a, name, position, send, set_data, stop.
do? possibly dangerous?

take control of leds on touch show 1 last pressed. can help?

this second contribution uses joystick , matrix modules. used them orientated rope @ top of modules.

joystick consists of 2 potentiometers , dial module, crossed @ centre. push-button switch included , activated pushing down in centre of joystick.
reading data joystick accomplished with:
jsk = joystick.data[n] n = 0 gives switch, n = 2 provides x , n = 3 y results. strings. if need calculations have change them integers or floats.

matrix consists of 64 white leds arranged in 8 rows of 8 origin (0,0) @ top left. rows , columns accessed values of 0 7.
matrix.set_pixel(x, y, state) state = 1 turns on pixel , 0 turns off. display not updated until .update() executed, either extension or separate command.

script moves pixel display until either button pushed or ctrl-c entered on keyboard.

code: select all

#!/usr/bin/env python3 #joystick , matrix - rope @ top #tony goodhew 18 oct 2016 import flotilla import time client = flotilla.client(     requires={         'one':flotilla.matrix,         'five':flotilla.joystick,         }) matrix = client.first(flotilla.matrix) joystick = client.first(flotilla.joystick)  matrix.clear().update() old_x = 0 old_y = 0 try:     sw = joystick.data[0] # string   switch - press straight down     swn = int(sw)         # integer     while (swn == 0):         x = int(joystick.data[1]) # range 0 1023         y = int(joystick.data[2])         x = 7 - int(x / 128)  # range 0 7         y = int(y / 128)         print(x,y)         matrix.set_pixel(old_x, old_y, 0).update() # turn old pixel off         matrix.set_pixel(x, y, 1).update()   # turn new pixel on         old_x = x         old_y = y         time.sleep(0.2)         swn = int(joystick.data[0])              matrix.clear().update()     client.stop()     print("stopped joystick button")  except keyboardinterrupt:     matrix.clear().update()     client.stop()     print("stopped ctrl-c") 


raspberrypi



Comments