From 242af86936e6b551321f2a73c4f7587a51d66315 Mon Sep 17 00:00:00 2001 From: Peter Ludikovsky Date: Wed, 2 Oct 2019 12:00:20 +0200 Subject: [PATCH] Inital Commit --- .gitignore | 1 + ColorStrip.ino | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE.txt | 24 ++++++++++++++++++++ README.md | 29 +++++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 .gitignore create mode 100644 ColorStrip.ino create mode 100644 LICENSE.txt create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eee4db0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.hex diff --git a/ColorStrip.ino b/ColorStrip.ino new file mode 100644 index 0000000..544d752 --- /dev/null +++ b/ColorStrip.ino @@ -0,0 +1,59 @@ +#include + +#define NUM_LEDS 50 +#define DATA_PIN 4 +#define INTR_PIN 2 +#define VIZUALIZATIONS 2 + +CRGB pixels[NUM_LEDS]; +unsigned char offset = 0; +void (*viz[VIZUALIZATIONS])(unsigned char); +volatile unsigned char currentViz = 0; + +void viz1(unsigned char offset) { + for (unsigned char i = 0; i < NUM_LEDS; i++) + pixels[(i + offset) % NUM_LEDS] = CRGB(128 + floor(127 * sin(2 * 3.1415926 * i / NUM_LEDS)), 0, 0); +} +void viz2(unsigned char offset) { + for (unsigned char i = 0; i < NUM_LEDS; i++) + pixels[i] = 0; + pixels[offset % NUM_LEDS] = CRGB(0x0F, 0xF, 0xF); + pixels[(offset + 1) % NUM_LEDS] = CRGB(0x1F, 0xE, 0xE); + pixels[(offset + 2) % NUM_LEDS] = CRGB(0x2F, 0xD, 0xD); + pixels[(offset + 3) % NUM_LEDS] = CRGB(0x3F, 0xC, 0xC); + pixels[(offset + 4) % NUM_LEDS] = CRGB(0x4F, 0xB, 0xB); + pixels[(offset + 5) % NUM_LEDS] = CRGB(0x5F, 0xA, 0xA); + pixels[(offset + 6) % NUM_LEDS] = CRGB(0x6F, 0x9, 0x9); + pixels[(offset + 7) % NUM_LEDS] = CRGB(0x7F, 0x8, 0x8); + pixels[(offset + 8) % NUM_LEDS] = CRGB(0x8F, 0x7, 0x7); + pixels[(offset + 9) % NUM_LEDS] = CRGB(0x9F, 0x6, 0x6); + pixels[(offset + 10) % NUM_LEDS] = CRGB(0xAF, 0x5, 0x5); + pixels[(offset + 11) % NUM_LEDS] = CRGB(0xBF, 0x4, 0x4); + pixels[(offset + 12) % NUM_LEDS] = CRGB(0xCF, 0x3, 0x3); + pixels[(offset + 13) % NUM_LEDS] = CRGB(0xDF, 0x2, 0x2); + pixels[(offset + 14) % NUM_LEDS] = CRGB(0xEF, 0x1, 0x1); + pixels[(offset + 15) % NUM_LEDS] = CRGB(0xFF, 0x0, 0x0); +} + +void changeViz(void) { + currentViz = (currentViz + 1) % VIZUALIZATIONS; +} + +void setup() { + FastLED.addLeds(pixels, NUM_LEDS); + FastLED.setBrightness(255); + for (int i = 0; i < NUM_LEDS; i++) + pixels[i] = CRGB(0, 0, 0); + FastLED.show(); + viz[0] = &viz1; + viz[1] = &viz2; + pinMode(INTR_PIN, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(INTR_PIN), changeViz, FALLING); +} + +void loop() { + (*viz[currentViz])(offset); + FastLED.show(); + delay(100); + offset++; +} diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..bbda492 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,24 @@ +Copyright (c) 2019 Peter Ludikovsky, All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions and + the following disclaimer in the documentation and/or other materials + provided with the distribution. + Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a9e931a --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +`/usr/space` ColorStrip +======================= + +Code für die LED-Beleuchtung beim Eingang zum `/usr/space` + +Specs +----- + +- Arduino UNO + - Data Pin: 4 + - Interrupt Pin: 2 +- LED Strip: + - 5m lang + - 10 Pixel/m + - 3 RGB-LEDs/Pixel + - WS2818B Controller + +Code +---- + +Neue Visualisierungen dürfen gerne hinzugefügt werden. Die Funktionen +dafür brauchen die Signatur `void func(unsigned char)` und müssen als +Funktions-Pointer zum Array `viz` hinzugefügt werden (in `setup()`). Der +einzige Parameter ist ein Offset, der nach jedem Tick (derzeit 100ms) +erhöht wird und im Bereich 0-255 liegt. + +In der Funktion selbst müssen die Farbwerte für jedes Pixel in das Array +`pixels` geschrieben werden, welches automatisch beim nächsten Refresh +ausgegeben wird.