Python Forum
Stop/continue While loop block
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stop/continue While loop block
#37
Yes.

I already have the 32 boards solder together, with its unique address assinged by the jumper on the back.

I already have it working via I2C, with the I2C pins on the Rasperry zero.

All of this is usingo the sample code from adafruit

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time

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

# create the i2c object for the trellis
i2c_bus = busio.I2C(SCL, SDA)

"""create the trellis. This is for a 2x2 array of NeoTrellis boards
for a 2x1 array (2 boards connected left to right) you would use:

trelli = [
    [NeoTrellis(i2c_bus, False, addr=0x2E), NeoTrellis(i2c_bus, False, addr=0x2F)]
    ]

"""
trelli = [
    [NeoTrellis(i2c_bus, False, addr=0x2E), NeoTrellis(i2c_bus, False, addr=0x2F)],
    [NeoTrellis(i2c_bus, False, addr=0x30), NeoTrellis(i2c_bus, False, addr=0x31)],
]

trellis = MultiTrellis(trelli)

# some color definitions
OFF = (0, 0, 0)
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)

# this will be called when button events are received
def blink(xcoord, ycoord, edge):
    # turn the LED on when a rising edge is detected
    if edge == NeoTrellis.EDGE_RISING:
        trellis.color(xcoord, ycoord, BLUE)
    # turn the LED off when a rising edge is detected
    elif edge == NeoTrellis.EDGE_FALLING:
        trellis.color(xcoord, ycoord, OFF)


for y in range(8):
    for x in range(8):
        # 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, PURPLE)
        time.sleep(0.05)

for y in range(8):
    for x in range(8):
        trellis.color(x, y, OFF)
        time.sleep(0.05)

while True:
    # the trellis can only be read every 17 millisecons or so
    trellis.sync()
    time.sleep(0.02)
This is the sample code for multitrellis, there is one for only one board



The only thing missing is the interrupt, so I can stop the trellis.sync at the While loop, so I can read data coming from serial.

Question: Is in theory possible to read only the data coming from the button pressed? I mean, when a press a button, the signal comes with the address data?

That would be a better solution, would take less time, instead of cheking all the boards with trellis.sync in the While loop.

Here is a weird behaviour that suggest it can be done better.

If I put a large time delay in the While loop and press many buttons before it reads again, when it reads I get all the button pressed together.
Reply


Messages In This Thread
Stop/continue While loop block - by Moris526 - Jan-02-2021, 09:54 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-02-2021, 12:30 PM
RE: Stop/continue While loop block - by Moris526 - Jan-02-2021, 11:35 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-03-2021, 12:22 AM
RE: Stop/continue While loop block - by Moris526 - Jan-03-2021, 12:30 AM
RE: Stop/continue While loop block - by Moris526 - Jan-03-2021, 01:06 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-03-2021, 11:23 AM
RE: Stop/continue While loop block - by Moris526 - Jan-03-2021, 01:37 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-03-2021, 04:33 PM
RE: Stop/continue While loop block - by Moris526 - Jan-04-2021, 01:08 AM
RE: Stop/continue While loop block - by bowlofred - Jan-04-2021, 01:15 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-04-2021, 02:05 AM
RE: Stop/continue While loop block - by Moris526 - Jan-04-2021, 02:28 AM
RE: Stop/continue While loop block - by Moris526 - Jan-04-2021, 02:39 AM
RE: Stop/continue While loop block - by Moris526 - Jan-04-2021, 07:29 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-04-2021, 10:05 AM
RE: Stop/continue While loop block - by Moris526 - Jan-05-2021, 02:21 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-05-2021, 08:01 PM
RE: Stop/continue While loop block - by Moris526 - Jan-06-2021, 06:58 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-06-2021, 10:44 AM
RE: Stop/continue While loop block - by Moris526 - Jan-06-2021, 11:07 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-06-2021, 11:45 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-09-2021, 05:51 AM
RE: Stop/continue While loop block - by Moris526 - Jan-09-2021, 06:58 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-11-2021, 04:00 PM
RE: Stop/continue While loop block - by Moris526 - Jan-11-2021, 08:02 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-11-2021, 10:53 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-13-2021, 03:34 AM
RE: Stop/continue While loop block - by Moris526 - Jan-13-2021, 08:14 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-14-2021, 09:10 PM
RE: Stop/continue While loop block - by Moris526 - Jan-15-2021, 10:01 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-15-2021, 12:48 PM
RE: Stop/continue While loop block - by Moris526 - Jan-15-2021, 06:18 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-15-2021, 10:18 PM
RE: Stop/continue While loop block - by Moris526 - Jan-16-2021, 03:16 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-16-2021, 05:35 PM
RE: Stop/continue While loop block - by Moris526 - Jan-17-2021, 09:25 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-17-2021, 07:05 PM
RE: Stop/continue While loop block - by Moris526 - Jan-18-2021, 01:02 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-18-2021, 05:11 PM
RE: Stop/continue While loop block - by Moris526 - Jan-18-2021, 10:03 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-18-2021, 11:59 PM
RE: Stop/continue While loop block - by Moris526 - Jan-19-2021, 10:58 AM
RE: Stop/continue While loop block - by Larz60+ - Jan-23-2021, 03:00 AM
RE: Stop/continue While loop block - by Moris526 - Jan-23-2021, 10:56 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-23-2021, 11:12 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-24-2021, 09:41 PM
RE: Stop/continue While loop block - by Moris526 - Jan-24-2021, 10:25 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-24-2021, 11:47 PM
RE: Stop/continue While loop block - by Moris526 - Jan-25-2021, 01:37 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-25-2021, 01:44 PM
RE: Stop/continue While loop block - by Moris526 - Jan-25-2021, 07:02 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-26-2021, 01:14 AM
RE: Stop/continue While loop block - by nilamo - Jan-26-2021, 06:41 PM
RE: Stop/continue While loop block - by Larz60+ - Jan-26-2021, 07:57 PM
RE: Stop/continue While loop block - by Moris526 - Jan-27-2021, 12:42 AM
RE: Stop/continue While loop block - by Larz60+ - Feb-01-2021, 10:36 AM
RE: Stop/continue While loop block - by Moris526 - Feb-01-2021, 08:11 PM
RE: Stop/continue While loop block - by Moris526 - Feb-09-2021, 11:23 PM
RE: Stop/continue While loop block - by Larz60+ - Feb-09-2021, 11:28 PM
RE: Stop/continue While loop block - by Moris526 - Feb-10-2021, 03:10 PM
RE: Stop/continue While loop block - by Moris526 - Mar-01-2021, 08:24 PM
RE: Stop/continue While loop block - by Larz60+ - Mar-01-2021, 09:45 PM
RE: Stop/continue While loop block - by Moris526 - Mar-24-2021, 06:29 PM
RE: Stop/continue While loop block - by Larz60+ - Mar-24-2021, 07:04 PM
RE: Stop/continue While loop block - by Moris526 - Mar-26-2021, 12:20 AM
RE: Stop/continue While loop block - by Larz60+ - Mar-26-2021, 01:32 AM
RE: Stop/continue While loop block - by Moris526 - Mar-28-2021, 04:13 PM
RE: Stop/continue While loop block - by Larz60+ - Mar-28-2021, 09:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Anyway to stop a thread and continue it? dimidgen 2 503 Mar-18-2024, 10:53 AM
Last Post: DeaD_EyE
  Button to stop while loop from another script Absolutewind 5 1,147 Sep-25-2023, 11:20 PM
Last Post: deanhystad
  get out of while loop and stop repeat Frankduc 11 3,343 Apr-26-2022, 10:09 PM
Last Post: deanhystad
  while loop will not stop looping TheTechRobo 5 3,965 Apr-20-2020, 01:47 PM
Last Post: TheTechRobo
  for loop stumbling block YoungGrassHopper 8 4,839 Sep-11-2019, 03:34 PM
Last Post: YoungGrassHopper
  while loop stumbling block YoungGrassHopper 5 3,518 Sep-09-2019, 08:36 PM
Last Post: YoungGrassHopper
  How to continue in loop until correct input received sunnyarora 10 10,306 May-04-2019, 02:37 PM
Last Post: Yoriz
  Can I Control loop with Keyboad key (start/stop) Lyperion 2 3,511 Jul-28-2018, 10:19 AM
Last Post: Lyperion
  build a list (add_animals) using a while loop, stop adding when an empty string is en nikhilkumar 1 9,036 Jul-17-2017, 03:29 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020