Building a light meter with Flotilla

Back in March I got my mega Flotilla treasure chest from Pimoroni. I was very excited to see what could be done with it. The Rockpool graphical interface is coming along nicely and I had some fun with that, but I really wanted to dig into the Python API.

flotilla - 1

Before you go any further check out this link from Pimoroni and this one from their website.

flotilla - 2

I wanted my first project to use both inputs and outputs so I decided to create a light meter which displayed the light level both on the number display and visually through a bar chart on the LED matrix.

flotilla - 5

This project uses the matrix connected to 1, a light sensor to 2 and the number display to 8. I screwed the components onto one of the base plates to keep them still!

flotilla - 6
#!/usr/bin/env python3

import flotilla
import time

client = flotilla.Client(
    requires={
        'one':flotilla.Matrix,
        'two':flotilla.Light,
        'eight':flotilla.Number
        })

matrix = client.first(flotilla.Matrix)
number = client.first(flotilla.Number)
light = client.first(flotilla.Light)

matrix.clear()
number.clear()

try:
    while True:

        time.sleep(0.5)
        matrix.clear()
        for y in range(8):
            matrix.set_pixel(7, y, True)
        for x in range(8):
            matrix.set_pixel(x,0, True)
        print (light.data)
        try:
            l_value = int(light.data[0])
            print(l_value)
            number.clear()
            number.set_number(l_value)
            number.update()
            if l_value in range (0,99):
                m_l_value = 0
            if l_value in range (100,199):
                m_l_value = 1
            if l_value in range (200,299):
                m_l_value = 2
            if l_value in range (300,399):
                m_l_value = 3
            if l_value in range (400,499):
                m_l_value = 4
            if l_value in range (500,599):
                m_l_value = 5
            if l_value in range (600,699):
                m_l_value = 6
            if l_value in range (700,799):
                m_l_value = 7
            if l_value in range (800,5000):
                m_l_value = 8
            print (m_l_value)
            for count in range(m_l_value):
                matrix.set_pixel(3,count+1,True)
                matrix.set_pixel(4,count+1,True)
            matrix.update()
        except Exception:
            pass
            
except KeyboardInterrupt:
    client.stop()

Leave a Reply

Your email address will not be published. Required fields are marked *