コード例 #1
0
def main():
    print('\nSetting up the system...')

    # Hyperparameters
    GRID_PATH = './grid/Grid.txt'
    N_LEDS = 100  # Number of leds of the strip
    STRIP_PIN = 4  # Pin D4
    TRIGGER_PIN = 26  # Pin D26
    ECHO_PIN = 25  # Pin D25

    # NeoPixel Strip object
    strip = neopixel.NeoPixel(Pin(STRIP_PIN), N_LEDS)
    print('\nStrip ready!')

    # Grid Object
    grid = matrix_read(GRID_PATH)
    grid = Grid(grid, strip=strip)
    print('Grid ready!')

    # Movement Sensor
    sensor_stream = Stream(l_max=7)
    sensor = HCSR04(trigger_pin=TRIGGER_PIN, echo_pin=ECHO_PIN)
    print('Sensor ready!')

    print('\nStarting the routines threads...')
    # Starting the routines in threads
    th.start_new_thread(senser, (sensor, sensor_stream))  # Senser thread
    th.start_new_thread(lighter, (grid, sensor_stream))  # Light thread
    print('Threads ready!')
コード例 #2
0
def main():
    print('\nSetting up the system...')

    # Hyperparameters
    GRID_PATH = './grid/Grid.txt'
    N_LEDS = 100  # Number of leds of the strip
    STRIP_PIN = 4  # Pin D4
    TRIGGER_PIN = 26  # Pin D26
    ECHO_PIN = 25  # Pin D25

    # NeoPixel Strip object
    strip = neopixel.NeoPixel(Pin(STRIP_PIN), N_LEDS)
    clear_strip(strip, N_LEDS)
    print('\nStrip ready!')

    # Grid Object
    grid = matrix_read(GRID_PATH)
    grid = Grid(grid, strip=strip)

    # We use the grid to compute the radial progression
    radial_progression = grid.radial_progression.copy()
    kwargs = {
        'radial_progression': radial_progression
    }
    # We use a Stream of states instead of a grid object
    grid_state = Stream(data=[], l_max=1, kwargs=kwargs)

    # Finally we delete the grid object
    del grid
    print('Grid ready!')

    # Movement Sensor
    sensor_stream = Stream(l_max=7)
    sensor = HCSR04(trigger_pin=TRIGGER_PIN, echo_pin=ECHO_PIN)
    print('Sensor ready!')

    print('\nStarting the routines threads...')
    # Starting the routines in threads
    # Senser thread
    th.start_new_thread(senser, (sensor, sensor_stream))
    # Light thread
    th.start_new_thread(lighter, (grid_state, strip, sensor_stream))
    print('Threads ready!')
コード例 #3
0
def grid_test(path, debug=False):
    grid = matrix_read(path)

    grid = Grid(grid, strip=[i for i in range(1, 101)])

    if debug:

        print(len(grid.state), len(grid.state[0]))

        print(grid.get_state_element(30, 4))
        print(grid.get_state_element(*grid.center))
        print(grid.pos_hash[2])
        print(grid.shape())

        print('progression')

        grid.gen_radial_progression()

        for i in grid.state:
            print(type(i))

    # setter and getter of elements and values in strip
    print('antes', grid.get_state_element_by_pos(30, 4))
    print('stream', grid.states)

    # LED 98
    print('LED 98')
    print('seteando...', grid.set_state_element_by_pos(30, 4, (255, 255, 255)))
    print('despues', grid.get_state_element_by_pos(30, 4))
    print('stream', grid.states)

    # LED 39
    print('LED 39')
    print('seteando...', grid.set_state_element_by_pos(26, 39,
                                                       (255, 255, 255)))
    print('despues', grid.get_state_element_by_pos(26, 39))
    print('stream', grid.states)

    # LED 39 -- again
    print('LED 39 -- again')
    print('seteando...', grid.set_state_element_by_num(39, (0, 230, 120)))
    print('despues', grid.get_state_element_by_pos(26, 39))
    print('stream', grid.states)

    # LED 21
    print('LED 21')
    print('seteando...', grid.set_state_element_by_num(21, (0, 230, 120)))
    print('despues', grid.get_state_element_by_num(21))
    print('stream', grid.states)
コード例 #4
0
# from machine import Pin
# from lib.hcsr04 import HCSR04
from lib.data_structures import Stream, Grid
from lib.utils import matrix_read
from lib.routines import senser, lighter
# import neopixel

# Hyperparameters
GRID_PATH = './grid/Grid.txt'
N_LEDS = 100  # Number of leds of the strip
STRIP_PIN = 4  # Pin D4
TRIGGER_PIN = 26  # Pin D26
ECHO_PIN = 25  # Pin D25

# NeoPixel Strip object
# strip = neopixel.NeoPixel(Pin(STRIP_PIN), N_LEDS)

false_strip = [i for i in range(1, N_LEDS + 1)]

# Grid Object
grid = matrix_read(GRID_PATH)
grid = Grid(grid, strip=false_strip)

# Movement Sensor
sensor_stream = Stream()
# sensor = HCSR04(trigger_pin=TRIGGER_PIN, echo_pin=ECHO_PIN)

# Starting the routines in threads
th.start_new_thread(senser, (sensor, sensor_stream))  # Senser thread
th.start_new_thread(lighter, (grid, sensor_stream))  # Light thread
コード例 #5
0
def grid_test(path, debug=False):
    grid = matrix_read(path)

    grid = Grid(grid, strip=[i for i in range(1, 101)])

    print('progression')

    print(grid.radial_progression)

    if debug:

        print(len(grid.state), len(grid.state[0]))

        print(grid.get_state_element(30, 4))
        print(grid.get_state_element(*grid.center))
        print(grid.pos_hash[2])
        print(grid.shape())

        print('progression')

        print(grid.radial_progression)

        for i in grid.state:
            print(type(i))

        # setter and getter of elements and values in strip
        print('antes', grid.get_state_element_by_pos(30, 4))
        print('stream', grid.states)

        # LED 98
        print('LED 98')
        print('seteando...', grid.set_state_element_by_pos(30, 4, (255, 255, 255)))
        print('despues', grid.get_state_element_by_pos(30, 4))
        print('stream', grid.states)

        # LED 39
        print('LED 39')
        print('seteando...', grid.set_state_element_by_pos(26, 39, (255, 255, 255)))
        print('despues', grid.get_state_element_by_pos(26, 39))
        print('stream', grid.states)

        # LED 39 -- again
        print('LED 39 -- again')
        print('seteando...', grid.set_state_element_by_num(39, (0, 230, 120)))
        print('despues', grid.get_state_element_by_pos(26, 39))
        print('stream', grid.states)

        # LED 21
        print('LED 21')
        print('seteando...', grid.set_state_element_by_num(21, (0, 230, 120)))
        print('despues', grid.get_state_element_by_num(21))
        print('stream', grid.states)

        # Annother test
        # Changes
        changes = ((i, 1, 2, 3) for i in range(1, 4))
        print('Changes 1')
        print('stream antes', grid.states)
        print('seteando...', grid.set_state_elements_by_num(changes))
        print('stream', grid.states)

        changes = ((i, 20, 20, 3) for i in range(1, 15))
        print('Changes 2')
        print('seteando...', grid.set_state_elements_by_num(changes))
        print('stream', grid.states)

        print('grid object size', get_size(grid))