Last active
January 29, 2024 23:40
-
-
Save Kevin-Prichard/d0f705cee7a171745cb6a48baf740119 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <MPU9250_asukiaaa.h> | |
#include <FastLED.h> | |
#define LED_PIN 5 | |
#define NUM_LEDS 144 | |
#define BRIGHTNESS 64 | |
#define LED_TYPE WS2811 | |
#define COLOR_ORDER GRB | |
#define DEBUG 1 | |
#define UPDATES_PER_SECOND 50 | |
CRGB leds[NUM_LEDS]; | |
int startIndex = 0; | |
CRGBPalette16 currentPalette; | |
TBlendType currentBlending; | |
extern CRGBPalette16 myRedWhiteBluePalette; | |
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM; | |
float gX, gY, gZ; | |
float aX, aY, aZ, aSqrt; | |
MPU9250 mySensor; | |
void init_mpu() { | |
Wire.begin(); | |
mySensor.setWire(&Wire); | |
mySensor.beginAccel(); | |
//mySensor.beginMag(); | |
mySensor.beginGyro(); | |
// you can set your own offset for mag values | |
// mySensor.magXOffset = -50; | |
// mySensor.magYOffset = -55; | |
// mySensor.magZOffset = -10; | |
} | |
int LED=0; | |
int LASTLED=0; | |
void init_fastled() { | |
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); | |
FastLED.setBrightness( BRIGHTNESS ); | |
// currentPalette = RainbowColors_p; | |
currentBlending = LINEARBLEND; | |
} | |
int trail(int index, int length, int direction) { | |
} | |
void setup() { | |
while(!Serial); | |
Serial.begin(115200); | |
Serial.println("started"); | |
init_mpu(); | |
init_fastled(); | |
LED=0; | |
LASTLED=0; | |
} | |
void loop() { | |
mySensor.accelUpdate(); | |
//mySensor.magUpdate(); | |
aX = mySensor.accelX(); | |
aY = mySensor.accelY(); | |
int color = 255 * ((aX + 1.0) / 2.0); | |
int value = 255 * ((aY + 1.0) / 2.0); | |
Serial.println("color:" + String(color)); | |
Serial.println("value:" + String(value)); | |
for( int i = 0; i < 16; i++) { | |
currentPalette[i] = CHSV(color, 255, value); | |
} | |
startIndex = startIndex + 5; /* motion speed */ | |
//FillLEDsFromPaletteColors(startIndex); | |
FastLED.clear(); | |
leds[value/2] = CHSV(color, 255, 128); | |
//leds[LASTLED] = CRGB::Purple; | |
//leds[LASTLED-1] = CRGB::Black; | |
FastLED.show(); | |
FastLED.delay(1000 / UPDATES_PER_SECOND); | |
} | |
void FillLEDsFromPaletteColors(uint8_t colorIndex) | |
{ | |
uint8_t brightness = 255; | |
for( int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = ColorFromPalette(currentPalette, colorIndex, brightness, currentBlending); | |
colorIndex += 3; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment