Guten Tag,
der im Anhang befindliche Sketch funktioniert sehr gut, aber die Steuerung kann nur über PIN 1 erfolgen. Ich möchte aber 7 Neo Pixel Stripes (1m 60 LED - zum testen habe ich 1m 30 LED) parallel ansteuern, also eigentlich dann PIN 1 bis PIN 7. Nun habe ich was von PortManipulation beim Arduino UNO gelesen, und das die Eingabe von
// alle Bits von Port D auf Ausgang
DDRD = B11111111;
PIN 0 bis PIN 7 parallel auf Ausgang schalten kann.
Geht das überhaupt in dem Sketch, ich habe keine Ahnung, weil ja PIN 1 fest eingegeben werden muß.
Wäre mein Anliegen eventuell auch mit einem 75HC595 lösbar? So ein Schieberegister kann doch auch 7 Ausgänge parallel ansteuern. Aber da wüßte ich jetzt auch nicht, wie ich das in den Sketch reinzaubern sollte.
Oder gibt es noch eine bessere Lösung, auf die ich mit meinem gefährlichen Halbwissen noch garnicht gekommen bin?
#include "FastLED.h"
#define NUM_LEDS 30
CRGB leds[NUM_LEDS];
#define PIN 1
void setup()
{
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
// *** REPLACE FROM HERE ***
void loop() {
BouncingBalls(0xff,0,0, 1);
}
void BouncingBalls(byte red, byte green, byte blue, int BallCount) {
float Gravity = -9.81;
int StartHeight = 1;
float Height[BallCount];
float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
float ImpactVelocity[BallCount];
float TimeSinceLastBounce[BallCount];
int Position[BallCount];
long ClockTimeSinceLastBounce[BallCount];
float Dampening[BallCount];
for (int i = 0 ; i < BallCount ; i++) {
ClockTimeSinceLastBounce[i] = millis();
Height[i] = StartHeight;
Position[i] = 0;
ImpactVelocity[i] = ImpactVelocityStart;
TimeSinceLastBounce[i] = 0;
Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
}
while (true) {
for (int i = 0 ; i < BallCount ; i++) {
TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
if ( Height[i] < 0 ) {
Height[i] = 0;
ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
ClockTimeSinceLastBounce[i] = millis();
if ( ImpactVelocity[i] < 0.01 ) {
ImpactVelocity[i] = ImpactVelocityStart;
}
}
Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
}
for (int i = 0 ; i < BallCount ; i++) {
setPixel(Position[i],red,green,blue);
}
showStrip();
setAll(0,0,0);
}
}
// *** REPLACE TO HERE ***
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}