Good evening, I have a quick question about my code, i’m really new to this still and a lot of it is way beyond me, but how would i go about anti-aliasing this code so the LEDs arent just on OR off. The code i have works well, it would just look alot nicer if the LEDs faded in and out rather than being all or nothing. I’ve referred to this example: https://plus.google.com/112916219338292742137/posts/2VYNQgD38Pw
but I dont even know where to start when it comes to integrating this into my code so it does something similar…
Here’s what i have:
#include<Wire.h>
const int MPU=0x68; // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp;
#include <FastLED.h> // FastLED library
#define NUM_LEDS 10 // Number of LED’s
#define COLOR_ORDER GRB // Change the order as necessary
#define LED_TYPE WS2811 // What kind of strip are you using?
#define BRIGHTNESS 255 // How bright do we want to go
CRGB Xleds[NUM_LEDS]; // Initialize our array
CRGB Yleds[NUM_LEDS];
void setup(){
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
LEDS.addLeds<LED_TYPE, 13, COLOR_ORDER>(Xleds, NUM_LEDS).setCorrection(TypicalLEDStrip);
LEDS.addLeds<LED_TYPE, 12, COLOR_ORDER>(Yleds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
void loop(){
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,8,true); // request a total of 14 registers
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
Serial.print("AcX = “); Serial.print(AcX);
Serial.print(” | AcY = “); Serial.print(AcY);
Serial.print(” | AcZ = “); Serial.print(AcZ);
Serial.print(” | Tmp = "); Serial.print(Tmp/340.00+36.53); //equation for temperature in degrees C from datasheet
// Figure out how many leds would be lit, and in what direction
int XLit = abs(AcX) / (25000/(NUM_LEDS/2));
int YLit = abs(AcY) / (25000/(NUM_LEDS/2));
// sanity check, just in case we get larger values than we’re expecting!
if(XLit > (NUM_LEDS/2)) {
XLit = NUM_LEDS/2;
}
// empty out the existing leds
fill_solid(Xleds,NUM_LEDS,CRGB::Black);
if(AcX < 0) {
// we want to light up numLit leds, starting from the midpoint, going down
for(int xi = 1; xi <= XLit; xi++) {
Xleds[(NUM_LEDS/2)-xi] = CRGB::Green;
}
} else {
// we want to light up numLit leds, starting from the midpoint, going forward
for(int xi = 0; xi < XLit; xi++) {
Xleds[(NUM_LEDS/2)+xi] = CRGB::Yellow;
}
}
// sanity check, just in case we get larger values than we’re expecting!
if(YLit > (NUM_LEDS/2)) {
YLit = NUM_LEDS/2;
}
// empty out the existing leds
fill_solid(Yleds,NUM_LEDS,CRGB::Black);
if(AcY < 0) {
// we want to light up numLit leds, starting from the midpoint, going down
for(int yi = 1; yi <= YLit; yi++) {
Yleds[(NUM_LEDS/2)-yi] = CRGB::White;
}
} else {
// we want to light up numLit leds, starting from the midpoint, going forward
for(int yi = 0; yi < YLit; yi++) {
Yleds[(NUM_LEDS/2)+yi] = CRGB::Red;
}
}
LEDS.show();
}