Python Forum

Full Version: Interrupt for Adafruits Neotrellis button/led board
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all.

I have 32 Adafruits Neotrellis boards (8x8 led/button) making a big led/button board, controlled with Raspberrypi zero.

Adafruits page says the interrupt works with python (https://learn.adafruit.com/adafruit-neotrellis?view=all) but in the sample code theres is not that function. It is in the Arduino code.
This is my first project so im trying to make it work.

I found some interrupt code for python (http://raspi.tv/2013/how-to-use-interrup...d-rpi-gpio)

I had no luck. Im trying different things but dont have enough knoledge.

Any help is welcomed

I need the interrupt because the time it takes to read the entire board is too much

The code I found is for a button, not a board .....so...



import RPi.GPIO as GPIO
import time
import serial

GPIO.setmode(GPIO.BCM) 
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)



ser=serial.Serial('/dev/ttyS0',57600 )

from board import SCL, SDA
import busio
from adafruit_neotrellis.neotrellis import NeoTrellis
from adafruit_neotrellis.multitrellis import MultiTrellis


i2c_bus = busio.I2C(SCL, SDA)


trelli = [
    [NeoTrellis(i2c_bus, False, addr=0x35), NeoTrellis(i2c_bus, False, addr=0x3A), NeoTrellis(i2c_bus, False, addr=0x4A), NeoTrellis(i2c_bus, False, addr=0x33), NeoTrellis(i2c_bus, False, addr=0x4B), NeoTrellis(i2c_bus, False, addr=0x45), NeoTrellis(i2c_bus, False, addr=0x4C), NeoTrellis(i2c_bus, False, addr=0x42)],
    [NeoTrellis(i2c_bus, False, addr=0x4D), NeoTrellis(i2c_bus, False, addr=0x3E), NeoTrellis(i2c_bus, False, addr=0x40), NeoTrellis(i2c_bus, False, addr=0x38), NeoTrellis(i2c_bus, False, addr=0x31), NeoTrellis(i2c_bus, False, addr=0x3D), NeoTrellis(i2c_bus, False, addr=0x3B), NeoTrellis(i2c_bus, False, addr=0x49)], 
    [NeoTrellis(i2c_bus, False, addr=0x2F), NeoTrellis(i2c_bus, False, addr=0x2E), NeoTrellis(i2c_bus, False, addr=0x3C), NeoTrellis(i2c_bus, False, addr=0x47), NeoTrellis(i2c_bus, False, addr=0x32), NeoTrellis(i2c_bus, False, addr=0x36),  NeoTrellis(i2c_bus, False, addr=0x48), NeoTrellis(i2c_bus, False, addr=0x3F)],
    [NeoTrellis(i2c_bus, False, addr=0x34), NeoTrellis(i2c_bus, False, addr=0x44), NeoTrellis(i2c_bus, False, addr=0x39), NeoTrellis(i2c_bus, False, addr=0x41), NeoTrellis(i2c_bus, False, addr=0x30), NeoTrellis(i2c_bus, False, addr=0x37),  NeoTrellis(i2c_bus, False, addr=0x43), NeoTrellis(i2c_bus, False, addr=0x46)],

]

trellis = MultiTrellis(trelli)


colos = {
    "a":(255,0,0),
    "b":(0,0,0),
}

def rgb(name):
    return colos[name]




def blink(xcoord, ycoord, edge):

    if edge == NeoTrellis.EDGE_RISING:

     print("d")
#     xc=str(xcoord)
#     out=xc.encode()
#     ser.write(out)
#     ser.write(b'a')
#     yc=str(ycoord)
#     up=yc.encode()

#     ser.write(up)
#     ser.write(b'a')
    elif edge == NeoTrellis.EDGE_FALLING:
      print("h")



#     xc=str(xcoord)

#     out=xc.encode()

#     ser.write(out)
#     ser.write(b'b')
#     yc=str(ycoord)
#     up=yc.encode()
#     ser.write(up)
#     ser.write(b'b')

for y in range(16):
    for x in range(32):
        # activate rising edge events on all keys
        trellis.activate_key(x, y, NeoTrellis.EDGE_RISING)
        # activate falling edge events on all keys
        trellis.activate_key(x, y, NeoTrellis.EDGE_FALLING)
        trellis.set_callback(x, y, blink)
        trellis.color(x,y, rgb("a"))
        time.sleep(0.01)

for y in range(16):
    for x in range(32):
        trellis.color(x, y, rgb("b"))
        time.sleep(0.01)





while True:
 
     
#    if (ser.inWaiting() > 0):
#      data=ser.readline()
#      c,v,j=data.split()
#      n=int(c)
#      m=int(v)
#      o=j.decode("utf-8")
#      trellis.color(n,m, rgb(o))
  


     
   try:
        GPIO.wait_for_edge(5, GPIO.FALLING):

        print("Nobody knows more about code than me, believe me")
   except KeyboardInterrupt:

       GPIO.cleanup()
    trellis.sync()
    time.sleep(0.02)