//Theatre-style crawling lights.
void theaterChase(struct WS2812B_Strip *strip, uint32_t c, const uint8_t delayTime)
{
  uint16_t pixelIndex, j;

  clear(strip);
  show(strip);

  for (pixelIndex = 0; pixelIndex < 3; pixelIndex++)
  {
	if (strip->breakFromPattern == true)
	{
	  return;
	}

    // Turn every third pixel on
    for (j = 0; j < strip->numberOfPixels; j += 3)
    {
      setPixelColor(strip, pixelIndex + j, c);
    }

    show(strip);
    delay_ms(delayTime);

    // Turn every third pixel off
    for (j = 0; j < strip->numberOfPixels; j += 3)
    {
      setPixelColor(strip, pixelIndex + j, 0);
    }
  }

  strip->inInterrupt = false;
  return;
}
void policeLights(struct WS2812B_Strip * strip, const uint32_t delayTime)
{
  // Flash every other pixel: RED,BLUE,RED,BLUE ... BLUE,RED,BLUE,RED ...
  uint16_t i;

  for (i = 0; i < strip->numberOfPixels; i += 2)
  {
    setPixelColor(strip, i, RED);
  }
  for (i = 1; i < strip->numberOfPixels; i += 2)
  {
    setPixelColor(strip, i, BLUE);
  }
  show(strip);
  delay_ms(delayTime);

  for (i = 0; i < strip->numberOfPixels; i += 2)
  {
    setPixelColor(strip, i, BLUE);
  }
  for (i = 1; i < strip->numberOfPixels; i +=2)
  {
    setPixelColor(strip, i, RED);
  }
  show(strip);
  delay_ms(delayTime);

  strip->inInterrupt = false;
  return;
}
void Adafruit_CircuitPlayground::senseColor(uint8_t& red, uint8_t& green, uint8_t& blue) {
  // Save the current pixel brightness so it can later be restored.  Then bump
  // the brightness to max to make sure the LED is as bright as possible for
  // the color readings.
  uint8_t old_brightness = strip.getBrightness();
  strip.setBrightness(255);
  // Set pixel 1 (next to the light sensor) to full red, green, blue
  // color and grab a light sensor reading.  Make sure to wait a bit
  // after changing pixel colors to let the light sensor change
  // resistance!
  setPixelColor(1, 255, 0, 0);  // Red
  delay(LIGHT_SETTLE_MS);
  uint16_t raw_red = lightSensor();
  setPixelColor(1, 0, 255, 0);  // Green
  delay(LIGHT_SETTLE_MS);
  uint16_t raw_green = lightSensor();
  setPixelColor(1, 0, 0, 255);  // Blue
  delay(LIGHT_SETTLE_MS);
  uint16_t raw_blue = lightSensor();
  // Turn off the pixel and restore brightness, we're done with readings.
  setPixelColor(1, 0);
  strip.setBrightness(old_brightness);
  // Now scale down each of the raw readings to be within
  // 0 to 255.  Remember each sensor reading is from the ADC
  // which has 10 bits of resolution (0 to 1023), so dividing
  // by 4 will change the range from 0-1023 to 0-255.  Also
  // use the min function to clamp the value to 255 at most (just
  // to prevent overflow from 255.xx to 0).
  red = min(255, raw_red/4);
  green = min(255, raw_green/4);
  blue = min(255, raw_blue/4);
}
/*
  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);
}
Exemple #5
0
//update the display while setting the date/time
void GoldieClock::displaySet(uint16_t pixel, uint32_t color)
{
    clear();
    for (uint16_t i = 0; i <= LAST_PIXEL; i += 5)    //hour markers
        setPixelColor(LAST_PIXEL - i, SET_MARKER);
    setPixelColor(LAST_PIXEL - pixel, color);
    show();
}
Exemple #6
0
static
void
handle_client(int client_socket) {
	uint8_t cmd;

	double bright;

	pos_t pos;
	col_t col;

	col_t pixels[64];
	
	int x, y;

	while (true) {
		recv_or_return(client_socket, &cmd, sizeof(char), 0);

		switch (cmd) {
			case UNICORND_CMD_SET_BRIGHTNESS:

				recv_or_return(client_socket, &bright, sizeof(double), 0);

				setBrightness(bright);
				break;

			case UNICORND_CMD_SET_PIXEL:

				recv_or_return(client_socket, &pos, sizeof(pos_t), 0);
				recv_or_return(client_socket, &col, sizeof(col_t), 0);

				setPixelColor(get_pixel_pos(pos.x, pos.y), col.r, col.g, col.b);
				break;

			case UNICORND_CMD_SET_ALL_PIXELS:
				recv_or_return(client_socket, &pixels, 64 * sizeof(col_t), 0);

				for (x = 0; x < 8; x++) {
					for (y = 0; y < 8; y++) {
						col_t *col = &pixels[x * 8 + y];
						setPixelColor(get_pixel_pos(x, y), col->r, col->g, col->b);
					}
				}

				break;

			case UNICORND_CMD_SHOW:

				show();
				break;

			default:

				close(client_socket);
				return;
		}
	}
}
void volMeter(uint8_t startColor, uint8_t endColor){
  if( checkButton() ){ return; };
  uint8_t  i;
  uint16_t minLvl, maxLvl;
  int      n, height;

  n   = analogRead(_pin_mic);                        // Raw reading from mic 
  n   = abs(n - 512 - _dc_offset); // Center on zero
  n   = (n <= _noise) ? 0 : (n - _noise);             // Remove noise/hum
  lvl = ((lvl * 7) + n) >> 3;    // "Dampened" reading (else looks twitchy)

  // Calculate bar height based on dynamic min/max levels (fixed point):
  height = _top_offset * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg);

  if(height < 0L)       height = 0;      // Clip output
  else if(height > _top_offset) height = _top_offset;
  if(height > peak)     peak   = height; // Keep 'peak' dot at top

  // Color pixels based on rainbow gradient
  for(i=0; i<_led_per_grp; i++) {
    if(i >= height)               setPixelColor(i,   0,   0, 0);
    else setPixelColor(i,Wheel(map(i,0,_led_per_grp-1,startColor,endColor)));
    
  }

  // Draw peak dot  
  if(peak > 0 && peak <= _led_per_grp-1) setPixelColor(peak,Wheel(map(peak,0,_led_per_grp-1,startColor,endColor)));
  
   strip.show(); // Update strip

  // Every few frames, make the peak pixel drop by 1:
    if(++dotCount >= _fall_rate) { //fall rate 
      
      if(peak > 0) peak--;
      dotCount = 0;
    }

  vol[volCount] = n;                      // Save sample for dynamic leveling
  if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter

  // Get volume range of prior frames
  minLvl = maxLvl = vol[0];
  for(i=1; i<SAMPLES; i++) {
    if(vol[i] < minLvl)      minLvl = vol[i];
    else if(vol[i] > maxLvl) maxLvl = vol[i];
  }
  // minLvl and maxLvl indicate the volume range over prior frames, used
  // for vertically scaling the output graph (so it looks interesting
  // regardless of volume level).  If they're too close together though
  // (e.g. at very low volume levels) the graph becomes super coarse
  // and 'jumpy'...so keep some minimum distance between them (this
  // also lets the graph go to zero when no sound is playing):
  if((maxLvl - minLvl) < _top_offset) maxLvl = minLvl + _top_offset;
  minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels
  maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average)
} 
Exemple #8
0
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();
	}
}
Exemple #9
0
void setVoltDisplay(uint32_t val) {
	uint8_t i;

	for (i=0; i < val/VOLTS_PER_PIXEL; i++) {
		setPixelColor(i, 0xff, 0, 0);
	}

	setPixelColor(i, 255*(val%VOLTS_PER_PIXEL)/VOLTS_PER_PIXEL, 0, 0);
	for (i++; i < NEOPIXEL_COUNT; i++) {
		setPixelColor(i, 0, 0, 0);
	}
	pixels.show();
}
Exemple #10
0
 void Image::thresholdFilter(double th)
 {
     for(int y = 0; y < m_height; y++) {
         for(int x = 0; x < m_width; x++) {
             Color c = pixelColorAt(x, y);
             if (c.luminance() > th) {
                 setPixelColor(x, y, kColorWhite);
             } else {
                 setPixelColor(x, y, kColorBlack);
             }
             
         }
     }
 }
//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);
    }

  }
}
void rainbow(struct WS2812B_Strip *strip, const uint8_t delayTime)
{
  uint16_t pixelIndex, j;

  clear(strip);
  show(strip);

  for(j = 0; j < 256; j++)
  {
	if (strip->breakFromPattern == true)
	{
	  return;
	}

	for(pixelIndex = 0; pixelIndex < strip->numberOfPixels; pixelIndex++)
    {
      setPixelColor(strip, pixelIndex, Wheel((pixelIndex+j) & 255));
    }

    show(strip);
    delay_ms(delayTime);
  }

  strip->inInterrupt = false;
  return;
}
Exemple #13
0
// Set pixel color from 'packed' 32-bit RGB color:
void PixelBone_Pixel::setPixelColor(uint32_t n, uint32_t c) {
  if (n < num_pixels) {
    uint8_t r = (uint8_t)(c >> 16);
    uint8_t g = (uint8_t)(c >> 8);
    uint8_t b = (uint8_t)c;
    setPixelColor(n, r, g, b);
  }
QImage YoonEncryptor::encrypt(const QImage &src)
{
    auto result = src;
    if(result.height() > result.width())
        result = result.transformed(QTransform().rotate(90));

    QVector<int> seed = dividers(result.height());
    int **lookUpTable = createLUT(seed);
    QImage tempImage;
    int red,green,blue;
    QColor oldColor;
    for(int r = 0; r < K; r++){
        tempImage = result;
        int **mask = createMask(result.height());
        for(int i = 0; i < result.height(); i++){
            for(int j = 0; j < result.width(); j++){
                oldColor = tempImage.pixelColor(j, i);
                red   = oldColor.red()^mask[lookUpTable[i][j]][j];
                green = oldColor.green()^mask[lookUpTable[i][j]][j];
                blue  = oldColor.blue()^mask[lookUpTable[i][j]][j];
                result.setPixelColor(j, lookUpTable[i][j], QColor(red, green, blue));
            }
        }
        freeMemory(mask, result.height());
    }
    freeMemory(lookUpTable, result.height());

    if(result.height() > result.width())
        result = result.transformed(QTransform().rotate(-90));
    return result;
}
Exemple #15
0
 // Set all pixels to a color (synchronously)
 void ColorSet(uint32_t color)
 {
     for (int i = 0; i < numPixels(); i++)
     {
         setPixelColor(i, color);
     }
     show();
 }
Exemple #16
0
void blowMap(const char* filename, double mapResolution, double robotSize)

{
	std::vector<unsigned char> image;
	unsigned width, height;
	unsigned x, y;
	unsigned error = lodepng::decode(image, width, height, filename);

	//if there's an error, display it
	if (error)
	{
		std::cout << "decoder error " << error << ": "
				<< lodepng_error_text(error) << std::endl;
	}

	double blowPixelFactor = (robotSize / mapResolution) / 4;
	std::vector<unsigned char> navImage;
	navImage.resize(width * height * 4);
		for (y = 0; y < height; y++)
			for (x = 0; x < width; x++) {
				if (image[y * width * 4 + x * 4 + 0]
						|| image[y * width * 4 + x * 4 + 1]
						|| image[y * width * 4 + x * 4 + 2])
				{
					setPixelColor(navImage, y, x, 255);
				}
			}
		for (y = 0; y < height; y++) {
			for (x = 0; x < width; x++) {
				if (!(image[y * width * 4 + x * 4 + 0]
						|| image[y * width * 4 + x * 4 + 1]
						|| image[y * width * 4 + x * 4 + 2]))
				{
					for (int i = -blowPixelFactor; i < blowPixelFactor; i++)
					{
						for (int j = -blowPixelFactor; j < blowPixelFactor; j++)
						{
							setPixelColor(navImage, y+i, x+j, 0);
						}
					}
				}
			}
		}

		encodeOneStep("newMap.png", navImage, width, height);
}
Exemple #17
0
int8_t	setStripColor(pixel_t strip[], uint8_t stripLen, uint8_t r, uint8_t g, uint8_t b) {
	if (stripLen < 0) return -1;
	uint8_t	i = 0;
	do {
		setPixelColor(&strip[i++], r, g, b);
	}	while (i < stripLen);
	return 0;
}
Exemple #18
0
void Zoa_WS2801::pushFront( rgbInfo_t color )
{
  byte* last = pixels + numLEDs*3 - 1;
  for ( byte* i = last - 3; i >= pixels; --i, --last )
  {
    *last = *i;
  }
  setPixelColor(0,color.r,color.g,color.b);
}
Exemple #19
0
void	clearStrip(pixel_t strip[], uint8_t stripLen) {
	uint8_t j;
	for (j=0; j<stripLen; j++) {
		setPixelColor(&strip[j], 0, 0, 0);
		//strip[j].r = 0;
		//strip[j].g = 0;
		//strip[j].b = 0;
	}
}
Exemple #20
0
void colorChase(uint32_t c, uint8_t wait) {
  int i;
  
  for (i=0; i < numLeds; i++) {
    setPixelColor(i, 0); // turn all pixels off
  }
  
  for (i=0; i < numLeds; i++) {
      setPixelColor(i, c);
      if (i == 0) {
        setPixelColor(numLeds-1, 0);
      } else {
        setPixelColor(i-1, 0);
      }
      lpd_show();
      _delay_ms(wait);
  }
}
Exemple #21
0
void Zoa_WS2801::setAll( rgbInfo_t color )
{
  setPixelColor(0,color.r,color.g,color.b);
  byte* end = pixels + numLEDs*3;
  byte* prev = pixels;
  for ( byte* i = pixels + 3; i < end; ++i, ++prev )
  {
    *i = *prev;
  }
}
Exemple #22
0
void Zoa_WS2801::pushBack( rgbInfo_t color )
{
  byte* last = pixels + numLEDs*3;
  byte* prev = pixels;
  for ( byte* i = pixels+3; i < last; ++i, ++prev )
  {
    *prev = *i;
  }
  setPixelColor(numLEDs-1,color.r,color.g,color.b);
}
void fillStripWithSolidColor(struct WS2812B_Strip *strip, const uint32_t color)
{
  uint16_t pixelIndex;

  for(pixelIndex = 0; pixelIndex < strip->numberOfPixels; pixelIndex++)
  {
	setPixelColor(strip, pixelIndex, color);
  }
  show(strip);
  return;
}
Exemple #24
0
// Set pixel color from separate 8-bit R, G, B components using x,y coordinate system:
void Adafruit_WS2801::setPixelColor(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b) {
  boolean evenRow = ((y % 2) == 0);
  // calculate x offset first
  uint16_t offset = x % width;
  if (!evenRow) {
    offset = (width-1) - offset;
  }
  // add y offset
  offset += y * width;
  setPixelColor(offset, r, g, b);
}
Exemple #25
0
//                            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);
    }
}
// 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);
  }
}
Exemple #28
0
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();
  }
}
Exemple #29
0
static void
unicornd_exit(int status)
{
	int i;

	for (i = 0; i < 64; i++) {
		setPixelColor(i,0,0,0);
	}

	show();
	terminate(0);
	exit(status);
}
Exemple #30
0
void	serial_processPacket(uint8_t const *buffer, pixel_t strip[], uint8_t const stripLen) {
	switch (buffer[0]) {
		case CMD_SET_PIXEL_COLOR:
			setPixelColor(&strip[buffer[0]], buffer[1], buffer[2], buffer[3]);
			break;
		case CMD_SET_STRIP_COLOR:
			setStripColor(strip, stripLen, buffer[0], buffer[1], buffer[2]);
			break;
		case CMD_LATCH:
			latchStrip(hardware_spi_write, NUM_LEDS);
			break;
	}
}