コード例 #1
0
ファイル: application.cpp プロジェクト: blinkingnoise/Sming
void TheaterChase() {
   int i,b=0;
   if (ChaseCycle > 0)
   {
  
	       if (TheaterChaseQ == 0) b=3;
	       if (TheaterChaseQ == 1) b=0;
	       if (TheaterChaseQ == 2) b=1;
	       if (TheaterChaseQ == 3) b=2;
	       
	   	   for (i=0; i < strip.numPixels(); i=i+4)
             strip.setPixelColor(i+b, 0);        //turn prev every third pixel off
	   	   
	   	   	for (i=0; i < strip.numPixels(); i=i+4)
               strip.setPixelColor(i+TheaterChaseQ, StripColor);    //turn every third pixel on
	   	   	
	   	   	strip.show();
	   	   	TheaterChaseQ++;
	   	   	if (TheaterChaseQ > 3)
	   	   	{
	   	   		TheaterChaseQ=0;
	   	   		ChaseCycle--;
	   	   	}
   }
   else
   {
	   // finish this demo
		StripDemoType++;         // next demo type
		TheaterChaseTimer.stop();   // stop this demo dimer
		StripDemoTimer.initializeMs(2000, StartDemo).start(true);  // start another demo after 2 seconds
   }	   
} 
コード例 #2
0
ファイル: rgb_sketch.cpp プロジェクト: thostr/neopixelstuff
void xmasRedGreenTwinkles(u16 runSec)
{
    const u8 flashOnDelayMs = 20;
    const u8 flashPauseMs = 150;
    const u8 numTwinklesPerSwap = 3;
    bool redOrGreenFirst = false;
    u32 startMs = millis();
    u8 numTwinklesToNextSwap = 0;
    while (millis() < startMs + runSec * 1000UL) {
        if (!numTwinklesToNextSwap--) {
            numTwinklesToNextSwap = numTwinklesPerSwap;
            redOrGreenFirst = !redOrGreenFirst;
        }
        u8 twinkleLedIdx = random(0, pixels.numPixels() - 1);
        pixels.setPixelColor(twinkleLedIdx, 0xffffff);
        pixels.show();
        delay(flashOnDelayMs);
        for (u8 i = 0; i < pixels.numPixels(); ++i) {
            u32 c = (i + redOrGreenFirst) & 1 ? 0xff0000 : 0x00ff00;
            pixels.setPixelColor(i, c);
        }
        pixels.show();
        delay(flashPauseMs);
    }
}
コード例 #3
0
ファイル: rgb_sketch.cpp プロジェクト: thostr/neopixelstuff
void smoothRunners(u16 runSec, u16 delayMs, struct Segment* segmentPtrIn, u8 numSegments)
{
    u16 superPosBuf[numSegments];
    u16 numSuperPositions = pixels.numPixels() << 8;
    u16 superPosOffset = numSuperPositions / numSegments;
    for (u8 i = 0; i < numSegments; ++i) {
        superPosBuf[i] = i * superPosOffset;
    }

    u32 startMs = millis();
    while (millis() < startMs + runSec * 1000UL) {
        clear(0, 0);
        Segment* segmentPtr = segmentPtrIn;
        for (u8 i = 0; i < numSegments; ++i) {
            u16 superPos = superPosBuf[i];
            superPos = wrapAdd(superPos, segmentPtr->speed, numSuperPositions);
            superPosBuf[i] = superPos;
            u8 numSegmentPixels = segmentPtr->lengthPercent * pixels.numPixels() / 100;
            if (numSegmentPixels < 2) {
                numSegmentPixels = 2;
            }
            drawTaperedSegment(superPos, numSegmentPixels, segmentPtr->color);
            ++segmentPtr;
        }
        pixels.show();
        delay(delayMs);
    }
}
コード例 #4
0
ファイル: rgb_sketch.cpp プロジェクト: thostr/neopixelstuff
void clear(u32 color, u16 clearMs)
{
    u16 delayMs = clearMs / pixels.numPixels();
    for (u16 i = 0; i < pixels.numPixels(); ++i) {
        pixels.setPixelColor(i, color);
        if (delayMs) {
            pixels.show();
            delay(delayMs);
        }
    }
}
コード例 #5
0
ファイル: arduino.cpp プロジェクト: takustaqu/bakkathon
// 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);
  }
}
コード例 #6
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);
}
コード例 #7
0
ファイル: arduino.cpp プロジェクト: takustaqu/bakkathon
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
        }
        strip.show();

        delay(wait);

        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, 0);        //turn every third pixel off
        }
    }
  }
}
コード例 #8
0
ファイル: arduino.cpp プロジェクト: takustaqu/bakkathon
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}
コード例 #9
0
ファイル: arduino.cpp プロジェクト: takustaqu/bakkathon
//NEOPIXEL LIBRARRY
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}
コード例 #10
0
ファイル: pixels.cpp プロジェクト: RockTheBike/lighting_test
// Fill the dots one after the other with a color
void setStrip(Adafruit_NeoPixel s, uint8_t r, uint8_t g, uint8_t b) {
	for (uint16_t i = 0; i < s.numPixels(); i++) {
		s.setPixelColor(i, r, g, b);
		//delay(wait);
	}
	s.show();
}
コード例 #11
0
void stripSet(uint32_t c, uint8_t wait) {
	for(uint16_t i=0; i<strip.numPixels(); i++) {
		strip.setPixelColor(i, c);
	}
	// move the show outside the loop
	strip.show();
	delay(wait);
}
コード例 #12
0
void pulseWhite(uint8_t wait) {
  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] ) );
    }
    delay(wait);
    strip.show();
  }

  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] ) );
    }
    delay(wait);
    strip.show();
  }
}
コード例 #13
0
// Set all pixels in the strip to a solid color, then wait (ms)
void colorAll(uint32_t c, uint8_t wait) {
  uint16_t i;
  
  for(i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
  }
  strip.show();
  delay(wait);
}
コード例 #14
0
ファイル: arduino.cpp プロジェクト: takustaqu/bakkathon
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);
  }
}
コード例 #15
0
void sprite(int num, uint32_t c0, uint32_t c1, uint32_t c2, int wait) {
		
	uint32_t colors[] = {c0, c1, c2};
	
	for (int i=0; i < num; i++){
		int colorIndex = random(3);
		strip.setPixelColor(random(strip.numPixels()), colors[colorIndex]);
	}
	
	strip.show();
	delay(wait);
}
コード例 #16
0
void colorWipeLeft(uint32_t c, uint8_t wait) {
  uint32_t off = pixels.Color(0,0,0);

  uint8_t trailSize = 5;

  for(uint16_t i=0; i<pixels.numPixels(); i++) {
    pixels.setPixelColor(i, c);
    if((i-trailSize)>=0) pixels.setPixelColor(i-trailSize,off);
    pixels.show();
    delay(wait);
  }
}
コード例 #17
0
void colorBeat(uint32_t c, uint8_t wait){
  for(int j=0;j<2;j++){
    for(uint16_t i=0; i<pixels.numPixels();i++){
      pixels.setPixelColor(i,c);
    }
    pixels.show();
    fade();
    delay(wait);
    pixels.setBrightness(200);
  }

}
コード例 #18
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);
    }
}
コード例 #19
0
ファイル: rgb_sketch.cpp プロジェクト: thostr/neopixelstuff
void drawTaperedSegment(u16 superPos, u8 numSegmentPixels, u32 color)
{
    u8 shiftPos = superPos & 0xff;
    u8 pixelPos = superPos >> 8;
    for (u8 i = 0; i <= numSegmentPixels; ++i) {
        u32 color1 = calcTaperedSegmentPixel(numSegmentPixels, i, color);
        u32 color2 = calcTaperedSegmentPixel(numSegmentPixels, i + 1, color);
        u32 avgColor = colorWeightedAvg(color1, color2, 255 - shiftPos);
        addPixelColor(pixelPos, avgColor);
        pixelPos = wrapAdd(pixelPos, 1, pixels.numPixels() - 1);
    }
}
コード例 #20
0
void colorWipeRight(uint32_t c, uint8_t wait) {
  uint32_t off = pixels.Color(0,0,0);
  uint16_t max_pixels = pixels.numPixels();

  uint8_t trailSize = 5;

  for(uint16_t i=0; i<=max_pixels; i++) {
    pixels.setPixelColor(max_pixels-i, c);
    if(i>=trailSize)pixels.setPixelColor(max_pixels-i+trailSize,off);
    pixels.show();
    delay(wait);
  }
}
コード例 #21
0
ファイル: pixels.cpp プロジェクト: RockTheBike/lighting_test
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));
		}
	}
}
コード例 #22
0
void TheaterChase() {
	 int i=0;
   if (ChaseCycle > 0)
   {
	 if  (TheaterChaseQ < 3 )
	 {
		 // erase previous

		 if (TheaterChaseQ!=0)
		 {
			 for (i=0; i < strip.numPixels(); i=i+3)
		                  strip.setPixelColor(i+TheaterChaseQ-1, 0);        //turn prev every third pixel off
		 }

         for (i=0; i < strip.numPixels(); i=i+3)
                        strip.setPixelColor(i+TheaterChaseQ, StripColor);    //turn every third pixel on
         strip.show();
         TheaterChaseQ++;
	 }
	 else
	 {
	   ChaseCycle--;
	   TheaterChaseQ=0;
	   // erase last one
		 for (i=0; i < strip.numPixels(); i=i+3)
	                  strip.setPixelColor(i+2, 0);        //turn every third pixel off last time
	     strip.show();
	 }

   }
   else
   {
	   // finish this demo
		StripDemoType++;         // next demo type
		TheaterChaseTimer.stop();   // stop this demo dimer
		StripDemoTimer.initializeMs(2000, StartDemo).start(true);  // start another demo after 2 seconds
   }
}
コード例 #23
0
void rainbow(uint8_t modulo, uint8_t wait)
{
    uint16_t i, j;

    for(j=0; j<256; j++) {
        for(i=0; i<strip1.numPixels(); i++) {
            if (i % modulo == 0) {
                strip1.setPixelColor(i, Wheel((i+j) & 255));
            } else {
                strip1.setPixelColor(i, 0);
            }
        }
        strip1.show();
        delay(wait);
    }
}
コード例 #24
0
void ColorWipe() {

	if (StripNo < strip.numPixels())
	{
		strip.setPixelColor(StripNo, StripColor);
		strip.show();
		StripNo++;
	}
	else
	{
		StripDemoType++;         // next demo type
		ColorWipeTimer.stop();   // stop this demo timer
		StripDemoTimer.initializeMs(2000, StartDemo).start(true);  // start next demo after 2 seconds
	}

}
コード例 #25
0
void colorLookHere(uint32_t c, uint8_t wait){
  uint32_t off = pixels.Color(0,0,0);
  uint16_t max_pixels = pixels.numPixels();
  uint16_t half_max_pixels = max_pixels/2;

  uint8_t trailSize = 3;

  for(uint16_t i=0;i<=half_max_pixels;i++){
    pixels.setPixelColor(half_max_pixels-i,c);
    pixels.setPixelColor(half_max_pixels+i,c);

    if((i-trailSize)>=0) pixels.setPixelColor(half_max_pixels+i-trailSize,off) ;
    if(i>=trailSize) pixels.setPixelColor(half_max_pixels-i+trailSize,off);
    pixels.show();
    delay(wait);
  }
}
コード例 #26
0
void SparkButton::rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) { // 1 cycle of all colors on wheel
    for(i=0; i< 12; i++) {
      uint8_t WheelPos = ((i * 256 / ring.numPixels()) + j) & 255;
      if(WheelPos < 85) {
         ring.setPixelColor(i,ring.Color(WheelPos * 3, 255 - WheelPos * 3, 0));
      } else if(WheelPos < 170) {
         WheelPos -= 85;
         ring.setPixelColor(i,ring.Color(255 - WheelPos * 3, 0, WheelPos * 3));
      } else {
         WheelPos -= 170;
         ring.setPixelColor(i,ring.Color(0, WheelPos * 3, 255 - WheelPos * 3));
      }
    }
    ring.show();
    delay(wait);
  }
}
コード例 #27
0
ファイル: ColorWipeEffect.cpp プロジェクト: rootux/sabaled
void ColorWipeEffect::tick(void) {
	// callcounter++;
	// if (callcounter % (*globalSpeedFactor) != 0)
	//  	return;
	 
	Section *sect = &sections[sectionsStart];
	Adafruit_NeoPixel *strip = sect->strip;

	// Fill the dots one after the other with a color
	int tempIndex = currentIndex;
	
	uint32_t tempColorValue = (uint32_t)*SabaleUtils::globalSourceColor;

    strip->setBrightness(tempIndex);
    strip->setPixelColor(tempIndex, tempColorValue);
    strip->show();

	currentIndex++;

	// Touched the end of the strip - go back to the start
	if (tempIndex == strip->numPixels()) {
		currentIndex = 0;
	}
}
コード例 #28
0
void whiteOverRainbow(uint8_t wait, uint8_t whiteSpeed, uint8_t whiteLength ) {

  if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;

  int head = whiteLength - 1;
  int tail = 0;
  int loops = 3;
  int loopNum = 0;
  static unsigned long lastTime = 0;

  while(true) {
    for(int j=0; j<256; j++) {
      for(uint16_t i=0; i<strip.numPixels(); i++) {
        if( (i >= tail && i <= head)
          || (tail > head && i >= tail)
          || (tail > head && i <= head) ) {
          strip.setPixelColor(i, strip.Color(0,0,0, 255 ) );
        } else {
          strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
        }
      }

      if(millis() - lastTime > whiteSpeed) {
        head++;
        tail++;
        if(head == strip.numPixels()) {
          loopNum++;
        }
        lastTime = millis();
      }

      if(loopNum == loops) return;

      head %= strip.numPixels();
      tail %= strip.numPixels();
      strip.show();
      delay(wait);
    }
  }

}
コード例 #29
0
void colorSet(uint32_t c) {
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, c);
    }
    strip.show();
}
コード例 #30
0
void ball(void)
{
    static double speed = 5;
    static double friction = 0.01;
    static double position = 0;
    
    double pi = 3.14159;
    MPU6050::Values values;
    double forceAngle = 00;
    double forceNorme = 0;
    uint8_t ii, count, led;
    Serial.print("position ");
    Serial.println(position);
    mpu.readValues(&values, NULL);
    Serial.print("x accel ");
    Serial.print(values.xAccel);
    Serial.print(" y accel ");
    Serial.println(values.yAccel);
    values.yAccel = -values.yAccel;
    if (values.xAccel == 0) {
        if (values.yAccel < 0) {
            forceAngle = -90;
        } else {
            forceAngle = 90;
        }
    } else {
        forceAngle = atan((double)values.yAccel / (double)values.xAccel) * 180 / pi;
        if (values.xAccel < 0) {
            forceAngle -= 180;
        }
    }
    forceNorme = sqrt(values.yAccel * values.yAccel + values.xAccel * values.xAccel);
    forceNorme = forceNorme / 50000.0;
    Serial.print("angle ");
    Serial.print(forceAngle);
    Serial.print(" diff angle ");
    Serial.print(position - forceAngle);
    Serial.print(" force ");
    Serial.println(sin((position - forceAngle) * pi / 180.0) * forceNorme);
    speed -= sin((position - forceAngle) * pi / 180.0) * forceNorme;
    if (speed > 0 && speed > friction) {
        speed -= friction;
    } else if (speed < 0 && -speed > friction) {
        speed += friction;
    } else {
        speed = 0;
    }
    position += speed;
    while (position > 360) {
        position -= 360;
    }
    while (position < 0) {
        position += 360;
    }
    count = strip1.numPixels();
    led = position * count / 360.0;
    for (ii = 0; ii < count; ii++) {
        if (led == ii) {
            strip1.setPixelColor(ii, 0x0f0f0f);
        } else {
            strip1.setPixelColor(ii, 0);
        }
    }
    Serial.print("position ");
    Serial.print(position);
    Serial.print(" speed ");
    Serial.print(speed);
    Serial.print(" led ");
    Serial.println(led);
    strip1.show();
}