Closed
Description
Hi there,
I'm try to use neopixels in an iot project.
I can run my script with
sudo python3 myscript.py
But i need to run neopixels as a python package from my script like
script_1.py
import time
import board
import neopixel
# Choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D18
# NeoPixels must be connected to D10, D12, D18 or D21 to work.
pixel_pin = board.D18
# The number of NeoPixels
num_pixels = 9
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
ORDER = neopixel.GRB
pixels = neopixel.NeoPixel(pixel_pin,
num_pixels,
brightness=0.2,
auto_write=True,
pixel_order=ORDER)
COLORS = {
'red': (255, 0, 0), # red
'green': (0, 255, 0), # green
'blue': (0, 0, 255), # blue
'white': (255, 255, 255), # white
'black': (0, 0, 0), # black
}
LED_PINS = {
'device_name_1': 0,
'device_name_2': 1,
'device_name_3': 2,
'device_name_4': 3,
'by': 4,
'gpk': 5,
'logo': 6,
'ec': 7,
'ph': 8,
}
def ctrl_led(led_num, color):
"""
@Param led num => [0 to 8]
@Param color list like (0, 255, 0)
"""
pixels[led_num] = COLORS['black']
time.sleep(0.125)
pixels[led_num] = color
script_2.py
from script_1 import ctrl_led, LED_PINS, COLORS
if False is pump_is_running:
ctrl_led(LED_PINS['ec'], COLORS['red'])
else:
ctrl_led(LED_PINS['ec'], COLORS['blue'])
Metadata
Metadata
Assignees
Labels
No labels