diff --git a/main.py b/main.py index 5d3c51c..2ac7c99 100644 --- a/main.py +++ b/main.py @@ -4,19 +4,12 @@ from datetime import datetime try: from rpi_ws281x import * import RPi.GPIO as GPIO - import socket + from flask import Flask + import json except ImportError: print('Some modules are missing. Try to install them with "pip3 install -r requirements.txt"') exit() -led_power = True -idle_mode = 1 -global power_button_pressed -power_button_pressed = False - -SOCKET_BIND_IP = '0.0.0.0' -SOCKET_BIND_PORT = 5760 - # LED strip configuration: LED_COUNT = 60 # Number of LED pixels. LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!). @@ -27,6 +20,9 @@ LED_BRIGHTNESS = 255 # 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 +mode = 0 +power = True + def debug_print(message: str): now = datetime.now() current_time = now.strftime("%H:%M:%S") @@ -44,9 +40,7 @@ def wheel(pos): def rainbowCycle(strip, wait_ms=5, iterations=10): for j in range(256*iterations): - if power_button_pressed == True: - break - elif idle_mode > 1: + if mode > 0: break for i in range(strip.numPixels()): strip.setPixelColor(i, wheel((int(i * 256 / strip.numPixels()) + j) & 255)) @@ -59,67 +53,98 @@ def setColor(strip, color, wait_ms=10): strip.show() time.sleep(wait_ms/1000.0) -def blink(strip, color1, color2): - for i in range(strip.numPixels()): - strip.setPixelColor(i, color1) - strip.show() - time.sleep(1) - for i in range(strip.numPixels()): - strip.setPixelColor(i, color2) - strip.show() - time.sleep(1) - -def change_idle_mode(channel): - global idle_mode - idle_mode += 1 - if idle_mode == 8: - idle_mode = 1 - debug_print('Change Idlemode executed') - -def power_toggle(channel): - if led_power == True: - led_power = False - debug_print('LED Power OFF') - else: - led_power = True - debug_print('LED Power ON') - if __name__ == '__main__': + app = Flask(__name__) + @app.route('/') + def index(): + return ''' + + + + + + + Server Rack LED stripe + + + +

My Server Rack LED stripe control API

+
+

Please use the following links to access the API:

+ +
+

How to use the API:

+