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