ATTiny85 a WS2812B

Uživatelský avatar
SkullKeep
Příspěvky: 290
Registrován: 23 srp 2017, 18:51
Reputation: 0
Bydliště: Brno
Kontaktovat uživatele:

Re: ATTiny85 a WS2812B

Příspěvek od SkullKeep » 02 úno 2019, 19:26

Nejde smazat nebo upravit můj příspěvěk, takže poslední úprava baragrafu:

Kód: Vybrat vše

#include <Adafruit_NeoPixel.h>
#define leftPin A2                                         // left audio in on fourth pin fro
#define stripPin PB0                                         // DIN of leds on second pin from top
#define stripNumOfLeds 30                                   // the total number of leds
#define ledBrightness  70                                   // 0 - 255, initial value (value read from the potentiometer if useSensorValues = true)
#define dropDelay  10                                       // hold time before dropping the leds
#define minValue  10                                      // min analog input value
#define maxValue  550                                       // max analog input value (0-1023 equals 0-5V)
#define overflowDelay  20                                  // overflow hold time
#define middleOffset  0                                     // offset for the middle led when using one strip
#define orangeLimitAmount 0                                // limit the amount of green of the middle LEDs to make them more orange 
#define sensitivityFactor 2                               //citlivost diod
/*************/
unsigned int stripColor[stripNumOfLeds / 2 - 1];                              // half of the number of leds + 1
boolean displayMiddleLed = false;                             // display the middle led (blue). set to true for one strip, false for two strips or rings
boolean splitStrip = true;                                    // set to true when using 2 strips or rings, false for one strip
float dropFactor = .9;                                    // value for dropping the leds
//******
int numOfSegments = stripNumOfLeds;
int halfNumOfSegments = numOfSegments / 2;
int stripMiddle = stripNumOfLeds / 2;
int maxDisplaySegments = stripNumOfLeds;
float ledFactor, ledFactor_div_numOfSegments;
int leftValue = 0;
int leftAnalogValue = 0;
int prevLeftValue = 0;
int prevLeftAnalogValue = 0;
int leftDropTime = 0;
int i;
unsigned int stripMiddleColor, stripOverflowColor, stripHoldColor;
//**************
Adafruit_NeoPixel strip = Adafruit_NeoPixel(stripNumOfLeds, stripPin, NEO_RGB + NEO_KHZ800);
//*************
void setup() {
  strip.begin();
  setStripColors();
  resetStrip();
}
//*****************8
void loop() {
  readValues();
  drawValues();
  prevLeftAnalogValue = leftAnalogValue;
  prevLeftValue = leftValue;
}
//*********************
void readValues() {
  leftAnalogValue = analogRead(leftPin);
  if (leftAnalogValue < prevLeftAnalogValue) {
    leftDropTime++;
    if (leftDropTime > dropDelay) {
      leftAnalogValue = prevLeftAnalogValue * dropFactor;
      leftDropTime = 0;
    }
    else
      leftAnalogValue = prevLeftAnalogValue;
  }
  leftValue = map(leftAnalogValue * sensitivityFactor, minValue, maxValue, 0, maxDisplaySegments);
  if (leftValue > maxDisplaySegments) {
    leftValue = maxDisplaySegments;
    drawOverflow();
  }
}
//************************
void drawValues() {
  if (splitStrip) {
    for (i = middleOffset; i < leftValue; i++)
    {
      strip.setPixelColor(i, stripColor[i]);
    }

    for (i = prevLeftValue; i > leftValue; i--)
    {
      strip.setPixelColor(i, 0);
    }
  }
  else {
    for (i = middleOffset; i < leftValue; i++)
    {
      strip.setPixelColor(stripMiddle + i, stripColor[i]);
    }

    for (i = prevLeftValue; i > leftValue; i--)
    {
      strip.setPixelColor(stripMiddle + i, 0);
    }
  }
  if (displayMiddleLed) {
    strip.setPixelColor(stripMiddle, stripMiddleColor);
  }
  strip.show();
}
//***************
void drawOverflow() {
  for (i = 0; i <= numOfSegments; i++) {
    strip.setPixelColor(stripMiddle + i, stripOverflowColor);
    strip.setPixelColor(stripMiddle - i, stripOverflowColor);
  }
  strip.show();
  delay(overflowDelay);

  for (i = 0; i <= numOfSegments; i++) {
    strip.setPixelColor(stripMiddle + i, 0);
    strip.setPixelColor(stripMiddle - i, 0);
  }
  strip.show();
}
//****************
void setStripColors() {
  int orangeLimit;
  ledFactor = (float)ledBrightness / 255;

  float orangeFactor = orangeLimitAmount / halfNumOfSegments;
  ledFactor_div_numOfSegments = ledFactor / numOfSegments;

  stripOverflowColor = strip.Color(min(255, 255 * ledFactor * 1.5), 0, 0);
  stripMiddleColor = strip.Color(0, 0, 255 * ledFactor);

  stripColor[0] = strip.Color(0, 255 * ledFactor, 0);
  for (i = 1; i <= numOfSegments; i++) {
    if (i <= halfNumOfSegments)
      orangeLimit = (i * orangeFactor);
    else
      orangeLimit = ((numOfSegments - i) * orangeFactor);

    stripColor[i] = strip.Color((255 * i * ledFactor_div_numOfSegments), ((255 - orangeLimit) * (numOfSegments - i) * ledFactor_div_numOfSegments), 0);
  }

  stripHoldColor = stripColor[numOfSegments];
}
//*********
void resetStrip() {
  for (i = 0; i <= numOfSegments; i++) {
    strip.setPixelColor(i, 0);
  }
  strip.show();
}
:twisted: :?: :arrow: :geek: P. Q. M.

NCPlyn
Příspěvky: 7
Registrován: 03 led 2019, 19:33
Reputation: 0

Re: ATTiny85 a WS2812B

Příspěvek od NCPlyn » 02 úno 2019, 19:44

Ten první fungoval ,ale svítil jenom zeleně. Druhý jenom svítí zelená - fialová - zelená .....

Uživatelský avatar
SkullKeep
Příspěvky: 290
Registrován: 23 srp 2017, 18:51
Reputation: 0
Bydliště: Brno
Kontaktovat uživatele:

Re: ATTiny85 a WS2812B

Příspěvek od SkullKeep » 02 úno 2019, 20:06

Zkus si pohrát s číslem u :

Kód: Vybrat vše

#define sensitivityFactor 2
změnou čísla dosáhneš i jiných barev, bohužel nemám víc jak 8 led diod na pásku.
:twisted: :?: :arrow: :geek: P. Q. M.

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 11 hostů