Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from rpi_ws281x import PixelStrip, Color
- import argparse
- import RPi.GPIO as GPIO
- import board
- import neopixel
- import colorsys
- # LED strip configuration:
- LED_COUNT = 150 # Number of LED pixels.
- LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
- # LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
- LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
- LED_DMA = 10 # DMA channel to use for generating signal (try 10)
- LED_BRIGHTNESS = 100 # Set to 0 for darkest and 255 for brightest
- LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
- LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
- # Create NeoPixel object with appropriate configuration.
- strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
- # Intialize the library (must be called once before other functions).
- strip.begin()
- SENSOR_PIN_1 = 23
- SENSOR_PIN_2 = 21
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(SENSOR_PIN_1, GPIO.IN)
- GPIO.setup(SENSOR_PIN_2, GPIO.IN)
- def my_callback1():
- wait_ms = 50
- color = Color(255, 0, 0)
- for i in range(strip.numPixels()):
- strip.setPixelColor(i, color)
- strip.show()
- time.sleep(wait_ms / 1000.0)
- def my_callback2():
- wait_ms = 50
- color = Color(0, 255, 0)
- for i in range(strip.numPixels()):
- strip.setPixelColor(i, color)
- strip.show()
- time.sleep(wait_ms / 1000.0)
- try:
- GPIO.add_event_detect(SENSOR_PIN_1, GPIO.RISING, callback=my_callback1)
- GPIO.add_event_detect(SENSOR_PIN_2, GPIO.RISING, callback=my_callback2)
- while True:
- print(f"SENSOR 1: {GPIO.input(SENSOR_PIN_1)}")
- print(f"SENSOR 2: {GPIO.input(SENSOR_PIN_2)}")
- time.sleep(2)
- except KeyboardInterrupt:
- print("BEENDE...")
- print("3...")
- time.sleep(1)
- print("2...")
- time.sleep(1)
- print("1...")
- time.sleep(1)
- print("ENDE")
Add Comment
Please, Sign In to add comment