from neopixel import NeoPixel from random import randrange import time import board from gpiozero import LED # ------------------------------------------------------------------------------ # Control script for 3D printer fan & LED control # # # Raspi Zero W Pin assignment, in order from top to bottom on PCB # # On PCB | Cable color | Raspberry PIN # -------------------------------------------- # 5V | not connected | ------ # LED | grey | GPIO 19 [PWM] # GND | black | ------ # DHT22 | white | GPIO 26 # FAN1 | purple | GPIO 13 # FAN2 | blue | GPIO 6 # SETTINGS = { 'fan1': board.D13, 'fan2': board.D6, 'dht': board.D26, 'led': board.D19, } fan1 = LED(SETTINGS['fan1']) fan2 = LED(SETTINGS['fan2']) def test_leds(sleep_time=0.1, num_leds_on_at_same_time=10, max_brightness=30): num_leds = 120 strip = NeoPixel(SETTINGS['led'], n=num_leds, auto_write=False) # switch all leds off for i in range(num_leds): strip[i] = (0, 0, 0) strip.show() for i in range(num_leds): strip[i] = tuple(randrange(0, max_brightness) for j in range(3)) if i - num_leds_on_at_same_time >= 0: strip[i-num_leds_on_at_same_time] = (0, 0, 0) strip.show() time.sleep(sleep_time) # switch all leds off again time.sleep(2) for i in range(num_leds): strip[i] = (0, 0, 0) strip.show() def board_test(fan_on_secs=4): print("Testing fan1") fan1.on() time.sleep(fan_on_secs) fan1.off() print("Testing fan2") time.sleep(fan_on_secs) fan2.off() print("Testing leds") test_leds() if __name__ == "__main__": board_test()