WS2812 LED Streifen als Bargraph

Hallo zusammen,

ich versuche, einen WS2812 Streifen mit 8 LEDs als Bargraph anzusteuern.
Der Streifen bekommt einen Wert (z_g_value) und soll in deren Abhängigkeit die LEDs ansteuern.

Ich würde mich freuen, wenn mir jemand auf die Sprünge hilft.

#include<math.h>
#include <Adafruit_NeoPixel.h>

#define PIN        3  // Pin der Neopixel
#define NUMPIXELS  8 // Wieviele Neopixel




const int x_out = A0; /* connect x_out of module to A1 of UNO board */
const int y_out = A1; /* connect y_out of module to A2 of UNO board */
const int z_out = A2; /* connect z_out of module to A3 of UNO board */
void setup() {
Serial.begin(9600);
strip.begin();
}
void loop() {
int x_adc_value,y_adc_value,z_adc_value;
double x_g_value, y_g_value,z_g_value; double roll, pitch, yaw;
double i;
x_adc_value = analogRead(x_out);
/* Digital value of voltage on x_out pin */
y_adc_value = analogRead(y_out);
/* Digital value of voltage on y_out pin */
z_adc_value = analogRead(z_out);
/* Digital value of voltage on z_out pin */
Serial.print("x = "); Serial.print(x_adc_value); Serial.print("\t\t"); Serial.print("y = "); Serial.print(y_adc_value); Serial.print("\t\t"); Serial.print("z = "); Serial.print(z_adc_value); Serial.print("\t\t");
x_g_value=(((double(x_adc_value*5)/1024) - 1.65 ) / 0.330 );
/* Acceleration in x-direction in g units */
y_g_value=(((double(y_adc_value* 5)/1024) - 1.65 ) / 0.330 );
/* Acceleration in y-direction in g units */
z_g_value=(((double(z_adc_value* 5)/1024) - 1.80 ) / 0.330 );
/* Acceleration in z-direction in g units */
roll = ( ( (atan2(y_g_value,z_g_value) * 180)/ 3.14 ) + 180 );
/* Formula for roll */
pitch=( ( (atan2(z_g_value,x_g_value)*180)/3.14 ) + 180 );
/* Formula for pitch */ yaw =( (atan2(x_g_value,y_g_value* 180) / 3.14 ) + 180 );
/* Formula for yaw */
/* Not possible to measure yaw using accelerometer. Gyroscope must be used if yaw is also required */
Serial.print("Roll = "); Serial.print(roll); Serial.print("\t"); Serial.print("Pitch = "); Serial.print(pitch); Serial.print("\n\n");


   
  }

delay(1000);
}

Danke

Schaue Dir bitte die Beispiele der Bibliothek an, funktioniert strandtest.ino?

Hallo,

jetzt must Du Dir erst mal überlegen ob es für die einzelnen Pixel nur die Zustände aus oder weiß gibt , oder ob der oberste Pixel auch gedimmt werden soll. Was soll mit der Farbe sein?

schau dir die Beispiele an und vestehe wie man die erste , zweite ... LED einschaltet. Ein einfacher Ansatz könnte sein das Du eine Schleife baust, darinnen dann eine if Abfragen auf Werte in einer linearen Abstufung. Abhängig davon schaltest Du die nexte LED an. Nach ende der Schleife gibt Du das dann mit LED.show() aus.

Als Ablauf etwa so
alle led aus
schleife i 0-7
wenn messwert > (i+1) * 1024/8 led (i) ein
schleife ende
led.show

Heinz