/* Fade from off to given color and back. */ void pulse(int w) { uint32_t c; //uint32_t c = Wheel(map(opt, 0, 1023, 0, 255)); for(uint16_t j = 8; j <= getOpt(_pin_lev, 0, 255); j++) { if( checkButton() ){ return; }; setBrightness(j); c = Wheel(map(opt, 0, 1023, 0, 255)); for(uint16_t i = 0; i < numPixels(); i++) { setPixelColor(i, c); } show(); delay(w); } delay(w*10+50); for(uint16_t j=getOpt(_pin_lev, 0, 255); j>8; j--) { if( checkButton() ){ return; }; setBrightness(j); c = Wheel(map(opt, 0, 1023, 0, 255)); for(uint16_t i = 0; i < numPixels(); i++) { setPixelColor(i, c); } show(); delay(w); } delay(w*10+50); }
void NeoPixel::kitLightTimer(bool enabled) { uint32_t color = 0xFF0000; // Hardcoded color to red int wait = 64; if (!enabled) { reset(); return; } for (uint16_t i = 0; i < numPixels(); i++) { setPixelColor(i, color); show(); delay(wait); if (i > 0) { setPixelColor(i-1, ((color & 0xFF0000) / 6) & 0xFF0000); setPixelColor(i-2, 0x000000); } show(); } for (uint16_t i = numPixels() - 1; i >= 0; i--) { setPixelColor(i, color); show(); delay(wait); if (i < numPixels()) { setPixelColor(i+1, ((color & 0xFF0000) / 6) & 0xFF0000); setPixelColor(i+2, 0x000000); } show(); } }
// Slightly different, this makes the rainbow equally distributed throughout // Same as above - just the other way around the chain void rainbowCycle_r(uint8_t wait) { uint16_t i, j; for(j=256*5; j>0; j--) { // 5 cycles of all colors on wheel for(i=0; i<numPixels(); i++) { setPixelColorT(i, Wheel(((i * 256 / numPixels()) + j) & 255)); } show(); usleep(wait * 1000); } }
// r a i n b o w C y c l e ( ) //================================================================================= //From Adafruit // Slightly different, this makes the rainbow equally distributed throughout // void GoldieClock::rainbowCycle(uint8_t wait, uint8_t repeatNumber) { for(uint16_t j = 0; j < 256U * repeatNumber; j++) { // repeatNumber of cycles of all colors on wheel for(uint16_t i=0; i< numPixels(); i++) { setPixelColor(i, wheel(((i * 256 / numPixels()) + j) & 255)); } show(); delay(wait); } }
void AdeniumRender::reset() { m_deviceRgbzPix->create(numPixels() * 16); int imgs[2]; imgs[0] = imageWidth(); imgs[1] = imageHeight(); adetrace::setImageSize(imgs); void * pix = m_deviceRgbzPix->map(); adetrace::resetImage((float4 *)pix, (uint)numPixels()); CudaBase::CheckCudaError(" reset image"); m_deviceRgbzPix->unmap(); }
void NeoPixel::toggleHeadLights(bool enabled) { kitLightEnabled = false; if (enabled) { reset(); setPixelColor(0, 0xFFFFFF); setPixelColor(1, 0XFFFFFF); setPixelColor(numPixels() - 1, 0xFFFFFF); setPixelColor(numPixels() - 2, 0xFFFFFF); show(); } else { reset(); } }
/* Loop through the given pattern */ void PixelUtil::patternLoop(byte pattern[][3], int pattern_size, int periodms) { static unsigned long next_time = millis(); static byte current = 0; if (millis() > next_time) { setPixelRGB(current, 0, 0, 0); current = (current + 1) % numPixels(); next_time += periodms; for (byte i = 0; i < pattern_size; i++) { setPixelRGB((current + i) % numPixels(), pattern[i][0], pattern[i][1], pattern[i][2]); } } }
//Rainbow Program void rainbowSingle() { setBrightness(); //int wait = getOpt(_pin_opt, -20, 20); uint16_t i, j; for(j = 0; j < 256; j++) { // calculate wait based on volatile opt from interrupt int wait = (int) map(opt, 0, 1023, -100, 100); if( wait < 0 ) { // negative values make a huge apparent difference, so fake a larger spread // by having -100 to 100 instead of -20 to 100 wait = floor( wait / 5 ); } // kind of a hack to allow negative wait value to speed rainbow by // skipping colors, otherwise 0 would be fast as chip could process if(wait < 0 && j % ( -1 * wait ) != 0){ continue; } if( checkButton() ){ return; }; for(i=0; i < numPixels(); i++) { setPixelColor(i, Wheel(j)); } show(); if(wait > 0){ delay(wait); } } }
// Slightly different, this makes the rainbow equally distributed throughout // Same as rainbowCycle() but does a colour wipe with a rainbow effect before starting the Cycle void rainbowCycle_wipe(uint8_t wait) { uint16_t i, j; j = 0; for(i=numPixels(); i>0; i--) { setPixelColorT(i, Wheel(((i * 256 / numPixels()) + j) & 255)); show(); usleep(50000); } // for(j; j<256*5; j++) { // 5 cycles of all colors on wheel // for(i=0; i<numPixels(); i++) { // setPixelColorT(i, Wheel(((i * 256 / numPixels()) + j) & 255)); // } // show(); // usleep(wait * 1000); // } }
//Theatre-style crawling lights. void theaterChase(Color_t c, uint8_t wait) { unsigned int j, q, i; for (j=0; j<15; j++) { //do this many cycles of chasing for (q=0; q < 3; q++) { for (i=0; i < numPixels(); i=i+3) { setPixelColorT(i+q, c); // Turn every third pixel on } show(); usleep(wait * 1000); for (i=0; i < numPixels(); i=i+3) { setPixelColor(i+q, 0, 0, 0); // Turn every third pixel off } } } }
// Fill the dots one after the other with a color void colorWipe(Color_t c, uint8_t wait) { uint16_t i; for(i=0; i<numPixels(); i++) { setPixelColorT(i, c); show(); usleep(wait * 1000); } }
// Fill the dots one after the other with a color // Same as above - just the other way around the chain void colorWipe_r(Color_t c, uint8_t wait) { int16_t i; for(i=numPixels()-1; i >= 0; i--) { setPixelColorT(i, c); show(); usleep(wait * 1000); } }
//Theatre-style crawling lights with rainbow effect void theaterChaseRainbow(uint8_t wait) { int j, q, i; for (j=0; j < 256; j+=4) { // cycle through every 4th color on the wheel for (q=0; q < 3; q++) { for (i=0; i < numPixels(); i=i+3) { setPixelColorT(i+q, Wheel((i+j) % 255)); //turn every third pixel on } show(); usleep(wait * 1000); for (i=0; i < numPixels(); i=i+3) { setPixelColor(i+q, 0, 0, 0); //turn every third pixel off } } } }
// Set all pixels to a color (synchronously) void ColorSet(uint32_t color) { for (int i = 0; i < numPixels(); i++) { setPixelColor(i, color); } show(); }
// Rainbow void rainbow(uint8_t wait) { uint16_t i, j; for(j=0; j<256; j++) { for(i=0; i<numPixels(); i++) { setPixelColorT(i, Wheel((i+j) & 255)); } show(); usleep(wait * 1000); } }
// Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i = 0; i < numPixels(); i++) { setPixelColor(i, c); if ( wait ) { show(); delay(wait); } } if ( wait == 0 ) { show(); } }
//Rainbow Program void rainbow() { int wait = getOpt(_pin_opt, 0, 255); uint16_t i, j; for(j = 0; j < 256; j++) { if( checkButton() ){ return; }; for(i = 0; i < numPixels(); i++) { setPixelColor(i, Wheel((i + j) & 255)); } show(); delay(wait); } }
void Adafruit_NeoPixel::emuCheckPixelIndex(int i) { do { if (i < 0) break; if (i > numPixels()) break; return; } while (false); posixino.printErrorPrefix(); fprintf(stderr,"invalid pixel index: %d \n",i); exit(1); } // emuCheckPixelIndex()
/** * "Rain Fall" effect - Test * @param c * @param wait [in ms] * @param sleepafert [in s] */ void RainFall(Color_t c,uint8_t wait,int sleepafter) { int j, k; j = (numPixels() / 2) - 1; k = j + 1; for (; j >= 0; j--,k++) { // printf("Pixel - %i %i\n", j, k); setPixelColorT(j, c); setPixelColorT(k, c); show(); usleep(wait * 1000); } sleep(sleepafter); //printf("Done:\n"); }
/** * This kit light method relies on exact timing in the main loop, * preferable 40ms for the best effect */ void NeoPixel::kitLightNoTimer() { uint32_t color = 0xFF0000; // red color if (!kitLightReverse) { if (kitLightTrail && kitLightState > 0) { setPixelColor(kitLightState, color); setPixelColor(kitLightState - 1, ((color & 0xFF0000) / 6) & 0xFF0000); setPixelColor(kitLightState - 2, 0x000000); kitLightTrail = false; } else if (kitLightState < numPixels()) { setPixelColor(kitLightState, color); kitLightState++; if (kitLightState == (numPixels() - 1)) { kitLightReverse = true; } else { kitLightTrail = true; } } } else { if (kitLightTrail && kitLightState < (numPixels() - 1)) { setPixelColor(kitLightState, color); setPixelColor(kitLightState + 1, ((color & 0xFF0000) / 6) & 0xFF0000); setPixelColor(kitLightState + 2, 0x000000); kitLightTrail = false; } else if (kitLightState >= 0) { setPixelColor(kitLightState, color); kitLightState--; if (kitLightState == 0) { kitLightReverse = false; } else { kitLightTrail = true; } } } show(); }
void LEDStrip::processStep() { // Here we will iterate through each LED on the active list // and process each step with respect to their individual slopes. for(int i = 0 ; i < numPixels(); i++){ leds[i].processStep(); uint32_t newColor = strip->Color(leds[i].curColor[0], leds[i].curColor[1], leds[i].curColor[2]); strip->setPixelColor(i, newColor); } delay(1); strip->show(); }
void Twinkle_Fade() { int j,i; for (i=0;i<15;i++) { for (j=0;j<numPixels();j++) { if (twinklearray[j] < 0.000) { twinklearray[j] = 0; setPixelColor(j, 0, 0, 0); } else if (twinklearray[j] > 0.000) { twinklearray[j] = twinklearray[j] - 0.1; if (twinklearray[j]<0) twinklearray[j] = 0; setPixelColor_B(j, 255, 255, 255,twinklearray[j]); } } show(); usleep(100000); } }
void Twinkle_T(Color_t c) { int j; for (j=0;j<numPixels();j++) { if (twinklearray[j] == 0) { // LED is off - Give it a chance to turn on. if ((rand() % 15) == 1) { // LED Got the change to be turned on now lets give it a random brightness level twinklearray[j] = (float) rand()/RAND_MAX; setPixelColorT_B(j, c, twinklearray[j]); } } else if (twinklearray[j] < 0.000) { twinklearray[j] = 0; setPixelColor(j, 0, 0, 0); } else if (twinklearray[j] > 0.000) { twinklearray[j] = twinklearray[j] - 0.1; if (twinklearray[j]<0) twinklearray[j] = 0; setPixelColorT_B(j, c, twinklearray[j]); } } show(); usleep(50000); }
//--------------------------------------------------------------------------- // Draw the major and minor tick marks //---------------------------------------------------------------------------- void VisusBorderAxis::renderTickMarks(const float borderWidth, const float borderLength, const BBAxis axis, const BBTickLine tickLineType) { // If drawing ticks is disabled, return if(!mDrawTicks) return; float low,high,minor_low,minor_high; float dimensions[2] = { borderLength, borderWidth }; int other = (axis+1) % 2; float width = dimensions[other]; float length = dimensions[axis]; // Get the current viewport GLdouble model[16]; GLdouble projection[16]; GLint viewport[4]; // x, y, width, height glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetIntegerv(GL_VIEWPORT,viewport); // Determine number of pixels per tick mark based on thickness (smallest 1) float minval = numPixels(model, projection, viewport, length, axis); const int numPixelPerMajorTick = std::max(1, (int)floor(minval*mMajorTickThickness)); const int numPixelPerMinorTick = std::max(1, (int)floor(minval*mMinorTickThickness)); float majorDelta = length / (mMajorTicks-1); float minorDelta = majorDelta / mMinorTicks; // Determine Tick Up/Down Positions low = minor_low = 0; high = minor_high = width; // If we need to draw tick on the normal side (below or right) if ((mTickPosition == AXIS_LOW) || (mTickPosition == AXIS_BOTH)) { low -= mMajorTickLength * width; // it needs to start this much below 0 minor_low -= mMinorTickLength * mMajorTickLength * width; } // If we need to draw tick on the opposite side (above or left) if ((mTickPosition == AXIS_HIGH) || (mTickPosition == AXIS_BOTH)) { high += mMajorTickLength * width; // it needs to end this much above the bar minor_high += mMinorTickLength * mMajorTickLength * width; } // Set the bounding box if (axis == BB_X_AXIS) { mDrawBox[0] = 0; mDrawBox[1] = low; mDrawBox[3] = length; mDrawBox[4] = high; } else { mDrawBox[0] = low; mDrawBox[1] = 0; mDrawBox[3] = high; mDrawBox[4] = length; } mWidth = width; mLength= length; mDrawAxis = axis; mDrawOther = other; if (! mDrawTicks) return; mTickColor.glColor(); // We can't change the thickness between a glBegin() and // glEnd(). Therefore, we first draw the major ticks then the minor // ones glLineWidth(numPixelPerMajorTick); glBegin(GL_LINES); float axisPosition = 0; for (int i=0;i<mMajorTicks; ++i, axisPosition+=majorDelta) { if (i==0 || i==(mMajorTicks-1)) drawTick(low, 0, axisPosition, BB_SOLID); else drawTick(low, high, axisPosition, tickLineType); } glEnd(); // Now draw the minor ticks glLineWidth(numPixelPerMinorTick); glBegin(GL_LINES); axisPosition = 0; for (int i=0;i<mMajorTicks-1; ++i, axisPosition+=majorDelta) { for (int j=0;j<mMinorTicks; ++j) { float position = axisPosition + (minorDelta*j); drawTick(minor_low, minor_high, position, tickLineType); } } glEnd(); }
void PixelUtil::setAllRGB(byte r, byte g, byte b) { for (uint16_t led = 0; led < numPixels(); led++) { leds[led] = CRGB(r, g, b); } }
void PixelUtil::setPixelRGB(PRGB *rgb) { if (rgb->pixel < numPixels()) { leds[rgb->pixel] = rgb->color(); } }
/* Rainbow Cycle Program - Equally distributed */ void rainbowCycle() { setBrightness(); uint16_t i, j; int j2; for(j=0; j<256; j++) { // cycle all wheel colors // calculate wait based on volatile opt from interrupt // This includes a very hacky way to have the color direction reverse // while maintaining the old "negative wait" convention to skip colors. // As it stands, we don't invert j2 till it reaches 0 otherwise colors would // suddenly change, but the direction may reverse a bit late (speeds up // before reversing). int wait = (int) map(opt, 0, 1023, -200, 200); if( wait < 0 ) { if( j2 > 0 || j == 1 ){ j2 = j; } else { j2 = -j; } wait = wait + 100; } else { if( j2 < 0 || j == 1 ){ j2 = -j; } else { j2 = j; } wait = -wait + 100; } if( wait < 0 ) { // negative values make a huge apparent difference, so fake a larger spread // by having -100 to 100 instead of -20 to 100 wait = floor( wait / 5 ); } // kind of a hack to allow negative wait value to speed rainbow by // skipping colors, otherwise 0 would be fast as chip could process if(wait < 0 && j % ( -1 * wait ) != 0){ continue; } if( checkButton() ){ return; }; for(i = 0; i < numPixels(); i++) { setPixelColor( i, Wheel( // i*256/numPixels() is like mapping i in 0...numPixels() to 0..256 // // + j & 255 ensures we change color each time we visit given pixel // while not running over 255 // // casting to uint32_t lets us handle strips longer than 256 pixels // since that would result in number larger than 32K, causing wraparound // to negative number ( (uint8_t) ( (uint32_t) i * 256 / numPixels()) + j2) & 255 ) ); } show(); if(wait > 0){ delay(wait); } } }
void PixelUtil::setAllRGB(uint32_t color) { for (uint16_t led = 0; led < numPixels(); led++) { setPixelRGB(led, color); } }
uint16_t LPD8806::index(uint16_t i) { return i % numPixels(); }
void testCMarginBuffer() { const int64_t cols = 23; const int64_t rows = 54; const int64_t numPixels = cols * rows; const int64_t numElements = (cols + 2 * margin) * (rows + 2 * margin); CMarginBuffer2D<margin> buffer1(cols, rows); EXPECT_EQ(cols, buffer1.cols()); EXPECT_EQ(rows, buffer1.rows()); EXPECT_EQ(numPixels, buffer1.numPixels()); EXPECT_EQ(numElements, buffer1.numElements()); // generate test data generateTestData(buffer1); // check the data in the buffer for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)), static_cast<Real>(x)), buffer1.pixel(x, y)); } } // create a compatible buffer auto buffer2 = buffer1.createCompatibleBuffer(); EXPECT_EQ(cols, buffer1.cols()); EXPECT_EQ(rows, buffer2.rows()); EXPECT_EQ(numPixels, buffer2.numPixels()); EXPECT_EQ(numElements, buffer2.numElements()); EXPECT_TRUE(buffer1.compatible(buffer2)); EXPECT_TRUE(buffer2.compatible(buffer1)); // copy the data in the new buffer buffer2.assign(buffer1); // clear the first buffer const Complex clearValue(42.0, -8.0); buffer1.setValue(clearValue); // check the data in the first buffer for (int64_t y = 0; y < rows; ++y) for (int64_t x = 0; x < cols; ++x) EXPECT_EQ(clearValue, buffer1.pixel(x, y)); // check the data in the second buffer for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)), static_cast<Real>(x)), buffer2.pixel(x, y)); } } // test addAssign buffer1.setValue(Complex(1.0, -1.0)); generateTestData(buffer2); buffer1 += buffer2; for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + R(1.0), static_cast<Real>(x) - R(1.0)), buffer1.pixel(x, y)); } } // test multiplyAssign(CMarginBuffer) buffer1.setValue(Complex(1.0, -1.0)); generateTestData(buffer2); buffer1 *= buffer2; for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + static_cast<Real>(x), -std::sin(static_cast<Real>(y)) + static_cast<Real>(x)), buffer1.pixel(x, y)); } } // test multiplyAssign(Complex) generateTestData(buffer1); buffer1 *= Complex(1.0, -1.0); for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + static_cast<Real>(x), -std::sin(static_cast<Real>(y)) + static_cast<Real>(x)), buffer1.pixel(x, y)); } } // test multiplyAssign(Real) generateTestData(buffer1); buffer1 *= 5.0; for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) * R(5.0), static_cast<Real>(x) * R(5.0)), buffer1.pixel(x, y)); } } // create a third buffer const Complex initialValue(-49.0, 7.0); CMarginBuffer2D<margin> buffer3(cols + 1, rows, initialValue); EXPECT_FALSE(buffer3.compatible(buffer1)); EXPECT_FALSE(buffer1.compatible(buffer3)); for (int64_t y = 0; y < rows; ++y) for (int64_t x = 0; x < cols; ++x) EXPECT_EQ(initialValue, buffer3.pixel(x, y)); std::mt19937 generator; std::uniform_real_distribution<Real> distribution(0.0, Math::twoPi); for (int64_t y = 0; y < rows; ++y) for (int64_t x = 0; x < cols + 1; ++x) buffer3.pixel(x, y) = fromArg(distribution(generator)); EXPECT_EQ(buffer3.numPixels(), buffer3.absSqrReduce()); // todo: test multiplyAssign // todo: test info }