#include <Arduino.h>
#include <FastLED.h>
#include <MPU6050_light.h>
#include "Wire.h"
#define NUM_LEDS 54
#define DATA_PIN 5
#define BRIGHTNESS 120
// This is an array of leds. One item for each led in your strip.
CRGB leds[NUM_LEDS];
MPU6050 mpu(Wire);
uint8_t offset = 0; // für rainbow usw. rotating "base color" used by many of the patterns
uint8_t speed = 30;
// für fire 2D
#define NUM_COLS 18
#define NUM_ROWS 3
// This function sets up the ledsand tells the controller about them
// für die beschl Werte:
unsigned long firetimer = 0;
float mx, my, mz, bx, by, bz, beschl;
void setup() {
delay(2000); // sanity check delay - allows reprogramming if accidently blowing power w/leds
Serial.begin(115200);
Wire.begin();
byte status = mpu.begin();
Serial.print(F("MPU6050 status: "));
Serial.println(status);
while (status != 0) {
} // stop everything if could not connect to MPU6050
Serial.println(F("Calculating offsets, do not move MPU6050"));
delay(1000);
mpu.calcOffsets(true, true); // gyro and accelero
Serial.println("Done!\n");
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness( BRIGHTNESS );
}
//JC
byte coordsX[NUM_LEDS] = { 255, 240, 225, 210, 195, 180, 165, 150, 135, 120, 105, 90, 75, 60, 45, 30, 15, 0, 0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 255, 240, 225, 210, 195, 180, 165, 150, 135, 120, 105, 90, 75, 60, 45, 30, 15, 0 };
byte coordsY[NUM_LEDS] = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
byte angles[NUM_LEDS] = { 130, 130, 131, 132, 133, 134, 137, 146, 191, 236, 245, 248, 250, 251, 252, 252, 252, 253, 2, 3, 3, 3, 4, 5, 7, 10, 19, 64, 109, 118, 121, 122, 123, 124, 125, 125, 120, 119, 118, 116, 113, 109, 101, 88, 64, 40, 26, 19, 15, 12, 10, 9, 8, 7 };
byte radii[NUM_LEDS] = { 224, 196, 168, 140, 113, 85, 58, 31, 14, 31, 58, 85, 113, 140, 168, 196, 224, 252, 252, 224, 196, 168, 140, 113, 85, 58, 31, 14, 31, 58, 85, 113, 140, 168, 196, 224, 227, 200, 173, 146, 119, 94, 70, 50, 42, 50, 70, 94, 119, 146, 173, 200, 227, 255 };
#define FRAMES_PER_SECOND 120
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
boolean autoplay = true;
uint8_t autoplaySeconds = 2;
/*
// Params for width and height für xy MAtrix
const uint8_t kMatrixWidth = 18;
const uint8_t kMatrixHeight = 3;
#define LAST_VISIBLE_LED 53
uint8_t XY (uint8_t x, uint8_t y) {
// any out of bounds address maps to the first hidden pixel
if ( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
return (LAST_VISIBLE_LED + 1);
}
const uint8_t XYTable[] = {
53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
};
uint8_t i = (y * kMatrixWidth) + x;
uint8_t j = XYTable[i];
return j;
}
*/
/* void Matrix24() {
EVERY_N_MILLIS(75) // falling speed
{
// move code downward
// start with lowest row to allow proper overlapping on each column
for (int8_t row = kMatrixHeight - 1; row >= 0; row--) {
for (int8_t col = 0; col < kMatrixWidth; col++) {
if (leds[XY(col, row)] == CRGB(175, 255, 175)) {
leds[XY(col, row)] = CRGB(27, 130, 39); // create trail
if (row < kMatrixHeight - 1)
leds[XY(col, row + 1)] = CRGB(175, 255, 175);
}
}
}
// fade all leds
for (int i = 0; i < NUM_LEDS; i++) {
if (leds[i].g != 255) leds[i].nscale8(192); // only fade trail
}
// check for empty screen to ensure code spawn
bool emptyScreen = true;
for (int i = 0; i < NUM_LEDS; i++) {
if (leds[i]) {
emptyScreen = false;
break;
}
}
// spawn new falling code
if (random8(3) == 0 ||
emptyScreen) // lower number == more frequent spawns
{
int8_t spawnX = random8(kMatrixWidth);
leds[XY(spawnX, 0)] = CRGB(175, 255, 175);
}
}
FastLED.setBrightness(BRIGHTNESS);
FastLED.show();
} */
/* void Feuer24() {
int a = millis();
for (int j = 0; j < NUM_ROWS; j++) {
for (int i = 0; i < NUM_COLS; i++) {
leds[XY(i, j)] = HeatColor(
qsub8(inoise8(i * 60, j * 60 + a, a / 3),
abs8(j - (NUM_ROWS - 1)) * 255 / (NUM_ROWS + 3)));
}
}
} */
/*
void rainbow()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(RainbowColors_p, offset + XY[i]);
}
} */
/* void loop() {
// Move a single white led
for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
// Turn our current led on to white, then show the leds
leds[whiteLed] = CRGB::White;
// Show the leds (only one of which is set to white, from above)
FastLED.show();
// Wait a little bit
delay(100);
// Turn our current led back to black for the next loop around
leds[whiteLed] = CRGB::Black;
}
} */
/* void loop() // Fastled example xymatrix
{
uint32_t ms = millis();
int32_t yHueDelta32 = ((int32_t)cos16( ms * (27/1) ) * (350 / kMatrixWidth));
int32_t xHueDelta32 = ((int32_t)cos16( ms * (39/1) ) * (310 / kMatrixHeight));
DrawOneFrame( ms / 65536, yHueDelta32 / 32768, xHueDelta32 / 32768);
if( ms < 5000 ) {
FastLED.setBrightness( scale8( BRIGHTNESS, (ms * 256) / 5000));
} else {
FastLED.setBrightness(BRIGHTNESS);
}
FastLED.show();
}
void DrawOneFrame( uint8_t startHue8, int8_t yHueDelta8, int8_t xHueDelta8)
{
uint8_t lineStartHue = startHue8;
for( uint8_t y = 0; y < kMatrixHeight; y++) {
lineStartHue += yHueDelta8;
uint8_t pixelHue = lineStartHue;
for( uint8_t x = 0; x < kMatrixWidth; x++) {
pixelHue += xHueDelta8;
leds[ XY(x, y)] = CHSV( pixelHue, 255, 255);
}
}
} */
/* void loop() { // feuer einfach hat funtioniert
int a = millis();
for (int j = 0; j < NUM_ROWS; j++) {
for (int i = 0; i < NUM_COLS; i++) {
//leds[XY(i,j)] = HeatColor(qsub8 (inoise8 (i * 60 , j * 60+ a , a /3),
//abs8(j - (NUM_ROWS-1)) * 255 / (NUM_ROWS+3)));
//leds[XY(i,j)] = CHSV (sin8(i*8+sin8(i*8+a/9))/2+sin8(j*8+sin8(j*8+a/8)/2),255,255);
leds[XY(i,j)] = CHSV (sin8((i<<4)+a/6)/2+sin8((j<<4)+a/6)/2,~0,~0);
}}
FastLED.show();
} */
/*
void loop() {
mpu.update();
// if(millis() - timer > 100){ // print data every second
Serial.print(F("ANGLE X: "));
Serial.print(mpu.getAngleX());
Serial.print("\tY: ");
Serial.print(mpu.getAngleY());
Serial.print("\tZ: ");
Serial.print(mpu.getAngleZ());
bx = 0;
by = 0;
bz = 0;
for (int i = 0; i < 10; i++) {
bx += mpu.getAccX();
by += mpu.getAccY();
bz += mpu.getAccZ();
delay(1);
}
bx /= 10;
by /= 10;
bz /= 10;
beschl = sqrt((bx * bx) + (by * by) + (bz * bz));
Serial.print(" beschl: ");
Serial.println(beschl); // Bereich zwischen 1.5 bis 2
// timer = millis();
//}
unsigned long firetime = 5000;
if (beschl > 2.5) {
long fstart = millis();
while ((fstart + firetime) > millis()) {
offset = beat8(speed);
rainbow();
FastLED.setBrightness(BRIGHTNESS);
FastLED.show();
// }
}
*/
// List of patterns to cycle through. Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList patterns = {
/* // 2D map examples:
clockwisePalette, //0
counterClockwisePalette, //1
outwardPalette, // 2 geht
inwardPalette, // 3 geht
northPalette, //4 geht nicht
northEastPalette, //5 geht nicht
eastPalette, //6 geht
southEastPalette, // 7 geht nicht
southPalette, // 8 geht niht
southWestPalette, // 9 geht nicht
westPalette, // 10 geht
northWestPalette, // 11 geht nicht */
// standard FastLED demo reel examples:
/* rainbow, // nö
rainbowWithGlitter,
confetti, // egal*/
sinelon, // blöd, weil nur in Streifenrichtung
// juggle, // hm ja
// bpm, // nun ja
};
const uint8_t patternCount = ARRAY_SIZE(patterns);
uint8_t currentPatternIndex = 0; // Index number of which pattern is current
CRGBPalette16 IceColors_p = CRGBPalette16(CRGB::Black, CRGB::Blue, CRGB::Aqua, CRGB::White);
const CRGBPalette16 palettes[] = {
RainbowColors_p,
RainbowStripeColors_p,
CloudColors_p,
LavaColors_p,
OceanColors_p,
ForestColors_p,
PartyColors_p,
HeatColors_p,
IceColors_p,
};
const uint8_t paletteCount = ARRAY_SIZE(palettes);
uint8_t currentPaletteIndex = 0;
CRGBPalette16 currentPalette = palettes[currentPaletteIndex];
boolean autoplayPalettes = false; //war true
uint8_t autoplayPaletteSeconds = autoplaySeconds * patternCount;
void loop()
{
// Call the current pattern function once, updating the 'leds' array
patterns[currentPatternIndex]();
offset = beat8(speed);
// do some periodic updates
EVERY_N_SECONDS(autoplaySeconds)
{
if (autoplay)
{
nextPattern(); // change patterns periodically
}
}
Serial.println(currentPatternIndex);
EVERY_N_SECONDS(autoplayPaletteSeconds)
{
// change palettes periodically
if (autoplayPalettes)
{
nextPalette();
}
}
// send the 'leds' array out to the actual LED strip
// FastLED.show(); called automatically, internally by FastLED.delay below:
// insert a delay to keep the framerate modest
FastLED.delay(1000 / FRAMES_PER_SECOND);
}
void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
currentPatternIndex = (currentPatternIndex + 1) % patternCount;
}
void nextPalette()
{
// add one to the current palette number, and wrap around at the end
currentPaletteIndex = (currentPaletteIndex + 1) % paletteCount;
currentPalette = palettes[currentPaletteIndex];
}
// 2D map examples:
void clockwisePalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + angles[i]);
}
}
void counterClockwisePalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - angles[i]);
}
}
void outwardPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - radii[i]);
}
}
void inwardPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + radii[i]);
}
}
void northPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - coordsY[i]);
}
}
void northEastPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - (coordsX[i] + coordsY[i]));
}
}
void eastPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - coordsX[i]);
}
}
void southEastPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - coordsX[i] + coordsY[i]);
}
}
void southPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + coordsY[i]);
}
}
void southWestPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + coordsX[i] + coordsY[i]);
}
}
void westPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + coordsX[i]);
}
}
void northWestPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + coordsX[i] - coordsY[i]);
}
}
// standard FastLED demo reel examples:
void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow(leds, NUM_LEDS, offset, 7);
}
void rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}
void addGlitter(fract8 chanceOfGlitter)
{
if (random8() < chanceOfGlitter)
{
leds[random16(NUM_LEDS)] += CRGB::White;
}
}
void confetti()
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy(leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV(offset + random8(64), 200, 255);
}
void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy(leds, NUM_LEDS, 20);
int pos = beatsin16(13, 0, NUM_LEDS - 1);
leds[pos] += CHSV(offset, 255, 192);
}
void bpm()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8(BeatsPerMinute, 64, 255);
for (int i = 0; i < NUM_LEDS; i++)
{ // 9948
leds[i] = ColorFromPalette(palette, offset + (i * 2), beat - offset + (i * 10));
}
}
const byte dotCount = 3;
const byte hues = 240 / dotCount;
void juggle()
{
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy(leds, NUM_LEDS, 20);
for (int i = 0; i < dotCount; i++)
{
leds[beatsin16(i + 7, 0, NUM_LEDS - 1)] |= CHSV(i * hues, 200, 255);
}
}