示例#1
0
/*
  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);
}
示例#2
0
	void mode_50_rainbowRotate(Led *led, Color color, int darkNum, int delayTime) {
		if(led->currentMode != 50){
			led->ledReset();
			led->currentMode = 50;
			led->delayTime = delayTime;
			led->status = 1;
			led->isRunning = true;
		} 
		int space = led->strip.numPixels() / darkNum;
		if((led->loopNum < 256 * 5) && led->ledTime % led->delayTime == 0)
		{
			for(uint16_t i=0; i< led->strip.numPixels(); i++) {
				led->strip.setPixelColor(i, Wheel((i * 256 / led->strip.numPixels() + led->loopNum) & 255, led));
				led->curLightStatus[i] = 1;
				led->curLightColor[i] = Wheel((i * 256 / led->strip.numPixels() + led->loopNum) & 255, led);
			}
			if(led->binaryValue < space){
				for (int i = 0; i < darkNum; i++)
				{
					led->strip.setPixelColor(led->binaryValue + space * i,0);
					led->curLightColor[led->binaryValue + space * i] = 0;
					led->curLightStatus[led->binaryValue + space * i] = 0;
				}	
				led->binaryValue++;
			} else if(led->binaryValue == space){
				led->binaryValue = 0;
			}
			led->strip.show();
			led->loopNum++;
		} else if(led->loopNum == 256 * 5){
			led->loopNum = 0;
		}
	}
示例#3
0
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)
} 
示例#4
0
RobotClass::RobotClass()
{
 	setRandomposition();
	setOrientation(rand() % 360);
  	setSpeed(80);
	setRadius(20);
  	setColor(1.0,1.0,1.0);
	wheelL = Wheel(75, x_coord, y_coord, orientation);
	wheelR = Wheel(75, x_coord, y_coord, orientation);
}
示例#5
0
RobotClass::RobotClass(GLfloat x, GLfloat y, int orient, int spd, int rad, string type)
{
	x_coord = x;
	y_coord = y;
	orientation = orient;
	speed = spd;
	radius = rad;
	wheelL = Wheel(spd, x, y, orient);
	wheelR = Wheel(spd, x, y, orient);
	robotType = type;
}
示例#6
0
void Sheet::rainbowPulseStrobe (int sh) {
	for(int j = 0 ; j < 255; j++) {
		for(int i = sheets[sh - 1]; i < sheets[sh]; i++) {
			strip.setPixelColor(i, Wheel(j));
			strip.setPixelColor(419 - i, Wheel(j));
		}
		strip.show();
		
		SetColor(sh, 0, 0, 0, true);
		delay(20);
	}
}
示例#7
0
void Sheet::rainbowPulse (int sh, int wait) {	
	for(int j = 0 ; j < 255; j++) {
		for(int i = sheets[sh - 1]; i < sheets[sh]; i++) {
			strip.setPixelColor(i, Wheel(j));
			strip.setPixelColor(419 - i, Wheel(j));
		}
		
		strip.show();
		
		delay(wait);
	}
}
示例#8
0
TripleOscillatorGui::TripleOscillatorGui(SafePtr<IControl> parent, TripleOscillator* osc):
	_osc(osc),
	Window(parent, 0, 0, 240, 260, osc->getSynthName().c_str()) {

	SafePtr<IControl> slider = safe_new(Slider(safePtr(), 0, 0, 0, -400, 600, &osc->_shift));
	SafePtr<IControl> frame = safe_new(Frame(safePtr(), 0, 0, 0, 0, 0));

        frame->adopt(osc->_adsr[0]->getGui());

	SafePtr<IControl> label1 = safe_new(Label(frame, 0, 0, "First oscillator"));

	SafePtr<IControl> frame3 = safe_new(Frame(frame, 0, 0, 0, 0, 0));
	SafePtr<PictureSelector> psel1 = safe_new(PictureSelector(frame3, 0, 0, 32, 32, &osc->_first_gen)).cast<PictureSelector>();
	SafePtr<IControl> exp = safe_new(IControl(frame3));  // expander to make pselector go left

	frame3->setPreferedSize(0, 34, 1);
	frame3->packHorizontally(5);

	SafePtr<IControl> label2 = safe_new(Label(frame, 0, 0, "Second oscillator"));

	SafePtr<IControl> frame1 = safe_new(Frame(frame, 0, 0, 0, 0, 0));
	SafePtr<PictureSelector> psel2 = safe_new(PictureSelector(frame1, 0, 0, 32, 32, &osc->_second_gen)).cast<PictureSelector>();
	SafePtr<IControl> wheel1_label = safe_new(Label(frame1, 0, 0, "Detune osc2"));
	SafePtr<IControl> wheel1 = safe_new(Wheel(frame1, 30, 5, 20, 20, -100.0, 100.0, &_osc->_first));
	wheel1_label->setPreferedSize(100, 20, 1);

	frame1->setPreferedSize(0, 34, 1);
	frame1->packHorizontally(5);

	SafePtr<IControl> label3 = safe_new(Label(frame, 0, 0, "Third oscillator"));

	SafePtr<IControl> frame2 = safe_new(Frame(frame, 0, 0, 0, 0, 0));
	SafePtr<PictureSelector> psel3 = safe_new(PictureSelector(frame2, 0, 0, 32, 32, &osc->_third_gen)).cast<PictureSelector>();
	SafePtr<IControl> wheel2_label = safe_new(Label(frame2, 0, 0, "Detune osc3"));
	SafePtr<IControl> wheel2 = safe_new(Wheel(frame2, 30, 5, 20, 20, -100.0, 100.0, &_osc->_second));
	wheel2_label->setPreferedSize(100, 20, 1);

	frame2->setPreferedSize(0, 34, 1);
	frame2->packHorizontally(5);

	frame->packVertically(5);

	packHorizontally(5);

	// Add generator images to picture selectors
	for (int i = 0; i < (int)GEN_NUMBER; ++i) {
		const char* filename = GeneratorFactory::inst()->getGeneratorPictureFilename((GeneratorType)i);
		psel1->addPicture(filename);
		psel2->addPicture(filename);
		psel3->addPicture(filename);
	}
}
示例#9
0
void Sheet::wipeUpRainbow (int sh) {
	int color = 0;
	while (color < 256) {
		wipeUp(sh, Wheel(color));
		color = color + 32;
	}
}
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;
}
示例#11
0
void set_vend(char c)
	{
	static unsigned char color_at = 0;
	static char lp = -1;
	static unsigned short larsen_at = 0;
	char i;
	uint32_t cur_color;

	if (lp != c)
		{
		color_at = 0;
		lp = c;
		larsen_at = 0;
		}

	for (i = 0; i < SODA_COUNT; i++)
		digitalWrite(sodas[i].relay_pin, c != i);
	if (c == -1 && larsen_on)
		{
		c = larsen_at / 256;
		cur_color = Color((larsen_at % 256), (larsen_at % 256), (larsen_at % 256));
		larsen_at++;
		if (larsen_at >= (256 * 8))
			larsen_at = 0;
		leds_two(c, ~cur_color, cur_color);
		}
	else
		{
		cur_color = Wheel(color_at++);
		leds_one(c, cur_color);
		}
	}
示例#12
0
void do_random_vend(unsigned char kind)
	{
	uint32_t randomSodaColor;
	unsigned char randomSoda, tries = 0;

	// Pick the color that the chosen soda will be
	randomSodaColor = Wheel(random() & 0xFF);
	// Display the light show
	randomColors(20, 5);
	log_msg("Vending random soda!");
	// Choose the random soda to vend
	while (--tries) /* Eventually break the loop if shit hits the fan */
		{
		randomSoda = random() % SODA_COUNT;
		if (sold_out & (1 << randomSoda))
			continue;
		if (kind == KIND_ANY)
			break;
		else if (kind == KIND_DIET && sodas[randomSoda].diet)
			break;
		else if (kind == KIND_REGULAR && !sodas[randomSoda].diet)
			break;
		}
	leds_one(randomSoda, randomSodaColor);
	digitalWrite(sodas[randomSoda].relay_pin, 0);
	log_msg("Random soda is %d!\n", randomSoda);
	// Let the chosen soda stay lit for one second
	delay(1000);
	// Turn off the LED
	leds_off();
	}
示例#13
0
//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
void rainbowCycle(uint8_t wait) {
	uint16_t i, j;
	j = 0;
	for(i=0; i<numPixels(); i++) {
		setPixelColorT(i, Wheel(((i * 256 / numPixels()) + j) & 255));
		show();
		usleep(50000);
	}
	for(j = 0; 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);
	}
}
示例#15
0
void LEDS::rainbow()
{
    _ledStrip.setPixelColor(firstRainbowIndex, Wheel((firstRainbowIndex + secondRainbowIndex) % 96));   
    _ledStrip.show();   // write all the pixels out

    if(firstRainbowIndex < _ledStrip.numPixels()) 
    {
        ++firstRainbowIndex;    
    }
    else
    {
        firstRainbowIndex = 0;
        if(secondRainbowIndex < 96 * 3) 
        {
            ++secondRainbowIndex;    
        }
        else
        {
            secondRainbowIndex = 0;
        }
     }
     Serial.print("first  ");
    Serial.println(firstRainbowIndex);
    Serial.print("second  ");
     Serial.println(secondRainbowIndex);

}
示例#16
0
void NeoPixelEffects::rainbow() {
    for (i = 0; i < _strip->numPixels(); i++) {
        _strip->setPixelColor(i, Wheel((i + j) & 255));
    }
    _strip->show();
    j++;
    j %= 256;
}
示例#17
0
int main(int argc, const char * argv[])
{
    std::cout << "Creating mMazda" << std::endl;
    Mazda* mMazda = new Mazda( Wheel() ) ;
    Ford* mFord = new Ford( Wheel() ) ;
    
    std::vector<Car*> mCarPointers;
    mCarPointers.push_back( mMazda );
    mCarPointers.push_back( mFord );
    
    for( auto carIt = mCarPointers.begin(); carIt != mCarPointers.end(); ++carIt){
        (*carIt)->drive();
        delete (*carIt);
    }
    
    return 0;
}
示例#18
0
void Colors::messageFlash(){
  for(byte i = 0; i < NEO_COUNT; i++)
    setColor(i, Wheel(((i * 256 / NEO_COUNT) + 5) & 255));
  pushColors();
  watch->getMotor()->pulseMotorRepeat(1023,150,50,2);
  watch->getMotor()->pulseMotor(1023, 250);
  delay(50);
}
 void rainbowCycle_B(uint8_t wait) {
   uint16_t i, j;
 
   for(j=0; j<256*1; j++) { 
     for(i=0; i< 13; i++) {
   
       strip_h.setPixelColor(i, Wheel(((i * 50 / 13) + j) & 255));
       delayMicroseconds(550);
     }
     for(k=0; k< 4; k++) {
       strip_d.setPixelColor(k, Wheel(((k * 50 / 4) + j) & 255));
       delayMicroseconds(550);
     }
     strip_d.show();
     strip_h.show();
    //   delay(wait);
   }
 }
// 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);
	}
}
示例#21
0
void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
示例#22
0
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
void rainbow(uint8_t wait) {
  int i, j;
   
  for (j=0; j < 256; j++) {     // 3 cycles of all 256 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel( (i + j) % 255));
    }  
    strip.show();   // write all the pixels out
    delay(wait);
  }
}
示例#24
0
	void mode_47_rainbowCycle(Led *led, int delayTime) {
		if(led->currentMode != 47){
			led->ledReset();
			led->currentMode = 47;
			led->delayTime = delayTime;
			led->status = 1;
			led->isRunning = true;
		} 
		if((led->binaryValue < 256 * 5) && led->ledTime % led->delayTime == 0)
		{
			for(uint16_t i=0; i< led->strip.numPixels(); i++) {
				led->strip.setPixelColor(i, Wheel((i * 256 / led->strip.numPixels() + led->binaryValue) & 255, led));
				led->curLightStatus[i] = 1;
				led->curLightColor[i] = Wheel((i * 256 / led->strip.numPixels() + led->binaryValue) & 255, led);
			}
			led->strip.show();
			led->binaryValue++;
		} else if((led->binaryValue == 256 * 5) && led->ledTime % led->delayTime == 0){
			led->binaryValue = 0;
		}
	}
// TODO: Integrate rainbowSequence to a game class, e.g: games.cpp/.h
void rainbowSequence(uint8_t wait){
  uint16_t i, j;


    for(j=0; j<256; j++) {
      for(i=0; i<pixels.numPixels(); i++) {
        pixels.setPixelColor(i, Wheel((i+j) & 255));
      }
      pixels.show();
      delay(wait);
    }
}
示例#26
0
//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);
  }
}
示例#27
0
	void mode_3_rainbowColor(Led *led, int delayTime){
		if(led->currentMode != 3){
			led->ledReset();
			led->currentMode = 3;
			led->delayTime = delayTime;
			led->isRunning = true;
			led->status = 1;
		} 
		if(led->binaryValue < 256 && led->ledTime % led->delayTime == 0)
		{
			for(uint16_t i=0; i<led->strip.numPixels(); i++) {
				led->strip.setPixelColor(i, Wheel(led->binaryValue,led));
				led->curLightColor[i] = Wheel(led->binaryValue,led);
				led->curLightStatus[i] = 1;
			}
			led->binaryValue++;
			led->strip.show();
		} else if(led->binaryValue == 256){
			led->binaryValue = 0;
		}
	}
void rainbowFade2White(uint8_t wait, int rainbowLoops, int whiteLoops) {
  float fadeMax = 100.0;
  int fadeVal = 0;
  uint32_t wheelVal;
  int redVal, greenVal, blueVal;

  for(int k = 0 ; k < rainbowLoops ; k ++) {
    for(int j=0; j<256; j++) { // 5 cycles of all colors on wheel
      for(int i=0; i< strip.numPixels(); i++) {
        wheelVal = Wheel(((i * 256 / strip.numPixels()) + j) & 255);

        redVal = red(wheelVal) * float(fadeVal/fadeMax);
        greenVal = green(wheelVal) * float(fadeVal/fadeMax);
        blueVal = blue(wheelVal) * float(fadeVal/fadeMax);

        strip.setPixelColor( i, strip.Color( redVal, greenVal, blueVal ) );
      }

      // First loop, fade in!
      if(k == 0 && fadeVal < fadeMax-1) {
        fadeVal++;
      }
      // Last loop, fade out!
      else if(k == rainbowLoops - 1 && j > 255 - fadeMax ) {
        fadeVal--;
      }

      strip.show();
      delay(wait);
    }
  }

  delay(500);

  for(int k = 0 ; k < whiteLoops ; k ++) {
    for(int j = 0; j < 256 ; j++) {
      for(uint16_t i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
      }
      strip.show();
    }

    delay(2000);
    for(int j = 255; j >= 0 ; j--) {
      for(uint16_t i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
      }
      strip.show();
    }
  }

  delay(500);
}
示例#29
0
void advanceAll(float wheelAdvance){
	for(int i = 0; i < NUM_STRIPS; i++){
		//setStrip(*strips[i], r, g, b);
		Adafruit_NeoPixel* strip = strips[i];
		for(uint16_t j = 0; j < strip->numPixels(); j++){
//			uint32_t t = strip->getPixelColor(j);
//			uint8_t r = (t >> 16) & 0xFF;
//			uint8_t g = (t >> 8) & 0xFF;
//			uint8_t b = t & 0xFF;
			strip->setPixelColor(j, Wheel(wheelAdvance));
		}
	}
}
void NeoPixelStripRainbow::loop() {
	int now = millis();
	int delay = now - last_color_change;
	
	if (delay >= wait) {
		for (i=1; i<strip->numPixels(); i++) {
			this->strip->setPixelColor(i, Wheel((i+j) & 255));
		}
		strip->show();
		this->last_color_change = millis();
	j = (j++) & 255;
	}
}