Example #1
1
void addPixelColor(u16 pixelPos, u32 addColor)
{
    u32 oldColor = pixels.getPixelColor(pixelPos);
    u32 newColor = additiveColorMix(oldColor, addColor);
    pixels.setPixelColor(pixelPos, newColor);
}
Example #2
0
void lightUp() {
  if (++colorIndex == NUM_COLORS) {
    colorIndex = 0;
  }

  int red = colorList[colorIndex][0];
  int green = colorList[colorIndex][1];
  int blue = colorList[colorIndex][2];

  // Bounds detection
  if (currentPixel == 0) {
    direction = 1;
  } else if (currentPixel == NUM_PIXELS) {
    direction = -1;
  }

  // Advancing the pixel
  currentPixel = currentPixel + (1 * direction);

  // now we will 'fade' it in 5 steps
  for (int x = 0; x < 5; x++) {
    int r = red * (x+1); r /= 5;
    int g = green * (x+1); g /= 5;
    int b = blue * (x+1); b /= 5;

    strip.setPixelColor(currentPixel, strip.Color(r, g, b));
    strip.show();
    delay(BLINK_DELAY);
  }

  // & fade out in 5 steps
  for (int x = 5; x >= 0; x--) {
    int r = red * x; r /= 5;
    int g = green * x; g /= 5;
    int b = blue * x; b /= 5;

    strip.setPixelColor(currentPixel, strip.Color(r, g, b));
    strip.show();
    delay(BLINK_DELAY);
  }
}
void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
inline void init_leds(){
	top_panels.begin();
	bottom_panels.begin();
	unsigned long int color = bottom_panels.Color(50,  0,  0 );
	set_all_leds(color);
}
Example #5
0
void update_pixel(int pixel, int r, int g, int b) {
  pixels.setPixelColor(pixel, pixels.Color(r, g, b));
  pixels.show();
}
Example #6
0
void Sheet::allRainbowPulse (uint8_t wait) {
	uint8_t i, j;
	
	for(j = 0 ; j < 255; j++) {
		for(i = 0; i < 30; i++) {
			strip.setPixelColor(i, Wheel(j));
			strip.setPixelColor(419 - i, Wheel(j));
		}
		
		for(i = 30; i < 60; i++) {
			strip.setPixelColor(i, Wheel((j+10)));
			strip.setPixelColor(419 - i, Wheel((j+10)));
		}
		
		for(i = 60; i < 90; i++) {
			strip.setPixelColor(i, Wheel((j+20)));
			strip.setPixelColor(419 - i, Wheel((j+20)));
		}
		
		for(i = 90; i < 120; i++) {
			strip.setPixelColor(i, Wheel((j+30)));
			strip.setPixelColor(419 - i, Wheel((j+30)));
		}
		
		for(i = 120; i < 150; i++) {
			strip.setPixelColor(i, Wheel((j+40)));
			strip.setPixelColor(419 - i, Wheel((j+40)));
		}
		
		for(i = 150; i < 180; i++) {
			strip.setPixelColor(i, Wheel((j+50)));
			strip.setPixelColor(419 - i, Wheel((j+50)));
		}
		
		for(i = 180; i < 210; i++) {
			strip.setPixelColor(i, Wheel((j+60)));
			strip.setPixelColor(419 - i, Wheel((j+60)));
		}
		
		strip.show();
		
		delay(wait);
	}
}
Example #7
0
void ExtendoHand::setupPins() {
    pinMode(VIBRO_PIN, OUTPUT);
    leds.begin();
}
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();
}
Example #9
0
void loop() {

  float vol_value = analogRead(VOLPIN);
  char str[5];
  int val;


  if(isDebug == 0 && isServoDone == 0){

        //for button
        buttonState = digitalRead(buttonPin);
        if (buttonState == HIGH) {
              //ボタンが押されたらサーボ起動、移動後にFlahsAirの初期化 (TODO 先に初期化するとサーボが動かないバグのため暫定)
              Serial.println("Btn High!!!!yeah");
              //時計周りに 0 度の方向へ、そして戻した後に、FAを起動
             moveServoShaft(0, 1);
             moveServoShaft(90, 1);
             delay(1000);
             isDebug = 1;
             // Initialize SD card.
             Serial.print(F("\nInitializing SD card..."));
               if (card.init(SPI_HALF_SPEED, chipSelectPin)) {
                 Serial.print(F("OK"));
               } else {
                 Serial.print(F("NG"));
                 abort();
               }
             memset(buffer, 0, 0x200);
          }else {
            //nothing
        }

        int d = Serial.read();
        if( d == 'a' ){
          sv.attach(SERVO_PIN);
        }
        else if( d == 'd' ){
          sv.detach();
        }
        else if( d == 'r' ){
          Serial.println(sv.read());
          Serial.println(sv.readMicroseconds());
        }
        else if( '0' <= d && d <= '9' ){
              //時計周りに 0 度の方向へそして戻してFA移動
             moveServoShaft(0, 10);
             moveServoShaft(90, 10);
             delay(1000);

             //サーボ終了
             isServoDone = 1;

             // Initialize SD card.
             Serial.print(F("\nInitializing SD card..."));
               if (card.init(SPI_HALF_SPEED, chipSelectPin)) {
                 Serial.print(F("OK"));
               } else {
                 Serial.print(F("NG"));
                 abort();
               }
             memset(buffer, 0, 0x200);

        }
      //}
  }else{

    if (card.readExtMemory(1, 1, 0x1000, 0x200, buffer)) {

      str[0] = buffer[0];
      str[1] = buffer[1];
      str[2] = buffer[2];
      str[3] = buffer[3];
      str[4] = 0;
      val = atoi(str);

        //0バイトの場合初期化
        if(currentByte != 0 && val == 0){
            strip.clear();
            strip.show();
            Serial.println("back to start");
            currentByte = 0;
        }

        if(val == 0 || val == currentByte){
          //do nothing...
          //Serial.println("get 1...");
        }else{

          if (vol_value < 800){
            //Serial.println("byte changed...");
            currentByte = val;
            showLed3AndHelloServo(val);
            Serial.println(val);
          }else{
            strip.clear();
            strip.show();
          }
        }
      }
  }
  delay(450);
}
void clearColorEars(){
  ears.setPixelColor(1,0,0,0);
  ears.setPixelColor(2,0,0,0);

  ears.show();
}
void fade(){
  for(int j =0; j<200; j++){
      pixels.setBrightness(200-j);
      delay(20);
  }
}
Example #12
0
void Sheet::BlackSpiral (uint8_t wait) {
	uint16_t i;
	for (i = 0; i < 30; i++) {
		strip.setPixelColor(i, 0);
		strip.setPixelColor(390 + i, 0);
		
		strip.setPixelColor(210 - i, 0);
		strip.setPixelColor(211 + i, 0);
		
		strip.setPixelColor(59 - i, 0);
		strip.setPixelColor(361 + i, 0);
		
		strip.setPixelColor(89 - i, 0);
		strip.setPixelColor(331 + i, 0);
		
		strip.setPixelColor(119 - i, 0);
		strip.setPixelColor(301 + i, 0);
		
		strip.setPixelColor(149 - i, 0);
		strip.setPixelColor(271 + i, 0);
		
		strip.setPixelColor(180 - i, 0);
		strip.setPixelColor(241 + i, 0);
		
		strip.show();
		delay(wait);
	}
}
//********************** ORDER EACH PIN to set the requested value
void go(int value1, int value2, int ctr, int ctg, int ctb, int flr, int flg, int flb, int frr, int frg, int frb, int blr, int blg, int blb, int brr, int brg, int brb){
/*
   Serial.println("**************************************");
   Serial.print("CENTER : ");
   Serial.print(ctr);
   Serial.print(",");
   Serial.print(ctg);
   Serial.print(",");
   Serial.print(ctb);
   Serial.println("");
   Serial.print("FRONT LEFT : ");
   Serial.print(flr);
   Serial.print(",");
   Serial.print(flg);
   Serial.print(",");
   Serial.print(flb);
   Serial.println("");
   Serial.print("FRONT RIGHT : ");
   Serial.print(frr);
   Serial.print(",");
   Serial.print(frg);
   Serial.print(",");
   Serial.print(frb);
   Serial.println("");
   Serial.print("BOT LEFT : ");
   Serial.print(blr);
   Serial.print(",");
   Serial.print(blg);
   Serial.print(",");
   Serial.print(blb);
   Serial.println("");
   Serial.print("BOT RIGHT : ");
   Serial.print(brr);
   Serial.print(",");
   Serial.print(brg);
   Serial.print(",");
   Serial.println(brb);
   Serial.println("---------------------------------------");
 */

        if(value1<0) {
                digitalWrite(M1,LOW);
                analogWrite(E1, abs(value1));
        }
        else{
                digitalWrite(M1,HIGH);
                analogWrite(E1, abs(value1));
        }

        if(value2<0) {
                digitalWrite(M2, LOW);
                analogWrite(E2, abs(value2));
        }
        else{
                digitalWrite(M2, HIGH);
                analogWrite(E2, abs(value2));
        }
        //Invidual leds installed in the ears
        //analogWrite(RL1, ctr);
        //analogWrite(GL1, ctg);
        //analogWrite(BL1, ctb);
        //analogWrite(RL2, ctr);
        //analogWrite(GL2, ctg);
        //analogWrite(BL2, ctb);
        //Leds in series used in the ears
        ears.setPixelColor(0, pixels.Color(ctr,ctg,ctb));
        ears.setPixelColor(1, pixels.Color(ctr,ctg,ctb));
        ears.show();


        int i;
        for (i=0; i<=3; i++)
                show_led_circle(i, frr,frg,frb);
        for (i=4; i<=9; i++)
                show_led_circle(i, brr,brg,brb);
        for (i=10; i<=15; i++)
                show_led_circle(i, blr,blg,blb);
        for (i=16; i<=20; i++)
                show_led_circle(i, flr,flg,flb);
}
Example #14
0
void Sheet::init () {
	strip.begin();
	strip.setBrightness(brightness); // Not really necessary, seems that the default of the library is max brightness
	strip.show(); // Initialize all pixels to 'off'
}
Example #15
0
void Sheet::update (bool show) {
	if (show) {
		strip.show();
	}
}
Example #16
0
void Sheet::allRainbowPulseStrobe () {
	int i;

	for(int j = 0 ; j < 255; j++) {
		for(i = 0; i < 30; i++) {
			strip.setPixelColor(i, Wheel(j));
			strip.setPixelColor(419 - i, Wheel(j));
		}
		
		for(i = 30; i < 60; i++) {
			strip.setPixelColor(i, Wheel((j+10)));
			strip.setPixelColor(419 - i, Wheel((j+10)));
		}
		
		for(i = 60; i < 90; i++) {
			strip.setPixelColor(i, Wheel((j+20)));
			strip.setPixelColor(419 - i, Wheel((j+20)));
		}
		
		for(i = 90; i < 120; i++) {
			strip.setPixelColor(i, Wheel((j+30)));
			strip.setPixelColor(419 - i, Wheel((j+30)));
		}
		
		for(i = 120; i < 150; i++) {
			strip.setPixelColor(i, Wheel((j+40)));
			strip.setPixelColor(419 - i, Wheel((j+40)));
		}
		
		for(i = 150; i < 180; i++) {
			strip.setPixelColor(i, Wheel((j+50)));
			strip.setPixelColor(419 - i, Wheel((j+50)));
		}
		
		for(i = 180; i < 210; i++) {
			strip.setPixelColor(i, Wheel((j+60)));
			strip.setPixelColor(419 - i, Wheel((j+60)));
		}
		strip.show();
		
		SetColor(1, 0, 0, 0, false);
		SetColor(2, 0, 0, 0, false);
		SetColor(3, 0, 0, 0, false);
		SetColor(4, 0, 0, 0, false);
		SetColor(5, 0, 0, 0, false);
		SetColor(6, 0, 0, 0, false);
		SetColor(7, 0, 0, 0, true);

		delay(20);
	}
}
Example #17
0
void colorSet(uint32_t c) {
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, c);
    }
    strip.show();
}
void show_led_circle(int number, int r, int g, int b) {
        pixels.setPixelColor(number, pixels.Color(r,g,b));
        pixels.show();
        return;
}
Example #19
0
File: main.cpp Project: alepar/nerf
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b) {
    pixels.setPixelColor(n, GAMMAS[r], GAMMAS[g], GAMMAS[b]);
}
void SparkButton::allLedsOn(uint8_t r, uint8_t g, uint8_t b){
    for(int i = 0; i<PIXEL_COUNT; i++){
            ring.setPixelColor(i, ring.Color(r, g, b));
    }
    ring.show();
}
Example #21
0
void showLed3AndHelloServo(int val){

      Serial.println("led array was....");
      Serial.println(val);
      Serial.println("ooooooooooooooooooo");

      //strip.clear();
      switch(val){
        case 123://how
          colorWipe(strip.Color(255, 255, 255), 100); // white
          colorWipe(strip.Color(0, 0, 0), 100); // black
                    colorWipe(strip.Color(255, 255, 255), 100); // white
                    colorWipe(strip.Color(0, 0, 0), 100); // black
                              colorWipe(strip.Color(255, 255, 255), 100); // white
                              colorWipe(strip.Color(0, 0, 0), 100); // black

          //TODO Arduinoをリセット
          wdt_enable(WDTO_15MS); // turn on the WatchDog and don't stroke it.
          for(;;) {
            // do nothing and wait for the eventual...
          }

          break;
        case 1://サーボ準備
          sv.attach(SERVO_PIN);
          Serial.println("servo attached...");//サーボの位置確認
          break;
        case 2://サーボ回転
          Serial.println(sv.read());//サーボの位置確認
          moveServoShaft(0, 10);
          //delay(100);//TODO 不要
          delay(1000);
          break;
        case 3://サーボ戻す
          Serial.println(sv.read());//サーボの位置確認
          moveServoShaft(90, 10);
          //delay(100);//TODO 不要
          delay(1000);
          break;
        case 4://サーボ終了
          sv.detach();
          break;
        case 0://クリア
          strip.clear();
          break;
        case 555://白
        case 5://白
          colorWipe(strip.Color(255, 255, 255), 80); // white
          delay(3000);
          colorWipe(strip.Color(0, 0, 0), 100); // black

          break;
        case 666://紫
        case 6://紫
            colorWipe(strip.Color(105, 14, 102), 80); // purple
            delay(3000);
            colorWipe(strip.Color(0, 0, 0), 100); // black
          break;
        case 777://ピンク
        case 7://ピンク
          colorWipe(strip.Color(252, 18, 245), 80); // pink
          delay(3000);
          colorWipe(strip.Color(0, 0, 0), 100); // black
          break;
        case 888://レインボー?
        case 8://レインボー?
          rainbow(20);
          //rainbowCycle(80);
          break;
        case 999://黒 = 消す
        case 9://黒 = 消す
          colorWipe(strip.Color(0, 0, 0), 10); // black
          strip.clear();
          break;
        case 100://予備
          break;
        default:
          Serial.println("this is for servo");
          colorWipe(strip.Color(0, 0, 0), 10); // black
          strip.clear();
          break;
      }
}
Example #22
0
void show() {
    // simply runs the frame
    strip.show();
}
void SparkButton::allLedsOff(){
    for(int i = 0; i<PIXEL_COUNT; i++){
            ring.setPixelColor(i, ring.Color(0, 0, 0));
    }
    ring.show();
}
Example #24
0
void loop() {
	mil = millis();
/*
  if( mil > when_next ){    // debug, mrygaj co 1 sek
		if( bitRead(sending, 0 ) ){  sendVal(0);}
		if( bitRead(sending, 1 ) ){  sendVal(1);}
		if( bitRead(sending, 2 ) ){  sendVal(2);}
		if( bitRead(sending, 3 ) ){  sendVal(3);}
		if( bitRead(sending, 4 ) ){  sendVal(4);}
		if( bitRead(sending, 5 ) ){  sendVal(5);}
		if( bitRead(sending, 6 ) ){  sendVal(6);}
		if( bitRead(sending, 7 ) ){  sendVal(7);}
		if( bitRead(sending, 8 ) ){  sendVal(8);}
		if(sending > 0){
			Serial.println();
		}
		when_next = mil + time;
	}*/
	if( pcb_type == 3 && divider-- == 0 ){
		boolean power = digitalRead( PIN_B3_POWER_SENSOR );
		if( power == LOW ){
			low_for_sure++;
			divider = PWR_SENSOR_DIV/2;		// high speed checking
			if( low_for_sure > 90 ){
				Serial.println("F0");
				Serial.flush();
			}
		}else{
			low_for_sure = 0;
			divider = PWR_SENSOR_DIV;
		}
	}
	
	readHall();
	step_servoY();
	step_servoZ();
	
	if(stepperIsReady){
		sendStepperReady();
		stepperIsReady = false;
	}
	/*
	if(pre--){
		int16_t val1 = analogRead( PIN_B2_WEIGHT );
		agv = (val1 + agv * 3)>>2;
		if( val1 - agv > 2 ){
			byte r = abs(val1 - agv);
			bottom_panels.setPixelColor(0, r,0,0 );
			bottom_panels.show();

		}else if( val1 - agv < 2 ){
			byte g = abs(val1 - agv);
			bottom_panels.setPixelColor(1, 0,g,0 );
			bottom_panels.show();
		}
	}*/

	if( mil - last_android > MAX_TIME_WITHOUT_ANDROID ){			// no android
		last_android	= mil;
		disableServosNow();
		stepperX.disableOutputs();
	//	unsigned long int color = bottom_panels.Color(20,  0,  0 );	
	//	set_all_leds(color);
		Serial.println("RRNOMASTER");
		Serial.flush();
	}
	if( servo_start_time != 0 ){
		unsigned long period = millis() - servo_start_time;
		if( period > SERVO_MAX_TIME ){		// emergency stop
			disableServosNow();
			servo_start_time = 0;
			unsigned long int color = bottom_panels.Color(255,  0,  0 );
			set_all_leds(color);
			Serial.println("RRSERVOOFF");
			Serial.flush();
		}
	}
	if( mil - last_poke > POKE_ANDROID_TIME ){			// no android
		Serial.print("POKE ");
		Serial.println(String(mil));
		Serial.flush();
		last_poke = mil;
	}
}
Example #25
0
void off(){
  for(int i=0;i<NUMPIXELS;i++){
    pixels.setPixelColor(i,0,0,0);
  }
  pixels.show();
}
Example #26
0
void loop()
{
    int runSec = 60;
    u16 numSegments;

    // Because I build the segment arrays in memory, I use both flash and sram for the segments and 5 is max for
    // what the ATtiny85 can handle with the current code. TODO: Try initializing the segments as const from literals.
    // That should cause them to stay in flash.
    const int maxSegments = 5;
    Segment segmentArr[maxSegments];

    // Xmas pattern and twinkles.
    xmasRedGreenTwinkles(runSec);

    // Example of simple debugging of something that only breaks when running on the device.
    //#ifdef Arduino_h
    //    debugMarker();
    //#endif

    // Halloween 1
    for (u8 i = 0; i < maxSegments; ++i) {
        segmentArr[i] = { 0xff6800, 30, 10 };
    }
    smoothRunners(runSec, 10, segmentArr, maxSegments);
    clear(pixels.Color(0, 0, 0), 1000);

//    // Halloween 2
//    for (u8 i = 0; i < maxSegments; ++i) {
//        segmentArr[i] = { 0xff6800, 30, 5 };
//    }
//    smoothRunners(runSec, 10, segmentArr, maxSegments);
//    clear(pixels.Color(0, 0, 0), 1000);

    // Halloween 3
    for (u8 i = 0; i < maxSegments; ++i) {
        segmentArr[i] = { 0xff6800, -60, 20 };
    }
    smoothRunners(runSec, 10, segmentArr, maxSegments);
    clear(pixels.Color(0, 0, 0), 1000);

    // RGB, even, short
    segmentArr[0] = { 0xff0000, 60, 8 };
    segmentArr[1] = { 0x00ff00, 60, 8 };
    segmentArr[2] = { 0x0000ff, 60, 8 };
    smoothRunners(runSec, 20, segmentArr, 3);
    clear(pixels.Color(0, 0, 0), 1000);

    // Took these out because I ran out of room on the ATtiny85.

//    // RGB, faster
//    segmentArr[0] = { 0xff0000, 120, 8 };
//    segmentArr[1] = { 0x00ff00, 120, 8 };
//    segmentArr[2] = { 0x0000ff, 120, 8 };
//    smoothRunners(runSec, 20, segmentArr, 3);
//    clear(pixels.Color(0, 0, 0), 1000);

//    // Misc colors, many short segments, even spacing
//    segmentArr[0] = { 0xff0000, 120, 2 };
//    segmentArr[1] = { 0x00ff00, 120, 2 };
//    segmentArr[2] = { 0x0000ff, 120, 2 };
//    segmentArr[3] = { 0xffff00, 120, 2 };
//    segmentArr[4] = { 0x00ffff, 120, 2 };
//    segmentArr[5] = { 0xff00ff, 120, 2 };
//    segmentArr[6] = { 0xfff000, 120, 2 };
//    segmentArr[7] = { 0x00fff0, 120, 2 };
//    segmentArr[8] = { 0x000fff, 120, 2 };
//    segmentArr[9] = { 0xfff000, 120, 2 };
//    segmentArr[10] = { 0x0fff00, 120, 2 };
//    segmentArr[11] = { 0x000fff, 120, 2 };
//    smoothRunners(runSec, 20, segmentArr, 12);
//    clear(pixels.Color(0, 0, 0), 1000);

//    // Misc colors, many short segments, uneven spacing
//    segmentArr[0] = { 0xff0000, 261, 2 };
//    segmentArr[1] = { 0x00ff00, 411, 2 };
//    segmentArr[2] = { 0x0000ff, 111, 2 };
//    segmentArr[3] = { 0xffff00, 125, 2 };
//    segmentArr[4] = { 0x00ffff, 163, 2 };
//    segmentArr[5] = { 0xff00ff, 188, 2 };
//    segmentArr[6] = { 0xfff000, 199, 2 };
//    segmentArr[7] = { 0x00fff0, 174, 2 };
//    segmentArr[8] = { 0x000fff, 175, 2 };
//    segmentArr[9] = { 0xfff000, 154, 2 };
//    segmentArr[10] = { 0x0fff00, 123, 2 };
//    segmentArr[11] = { 0x000fff, 100, 2 };
//    smoothRunners(runSec, 20, segmentArr, 12);
//    clear(pixels.Color(0, 0, 0), 1000);

    // Randomly colored single dots going both directions.
    for (u8 i = 0; i < maxSegments; ++i) {
        segmentArr[i].color = random(0, 0xffffff);
        if (random(0, 1)) {
            segmentArr[i].speed = random(100, 200);
        }
        else {
            segmentArr[i].speed = random(-100, -200);
        }
        segmentArr[i].lengthPercent = 10;
    };
    smoothRunners(runSec, 20, segmentArr, maxSegments);
    clear(pixels.Color(0, 0, 0), 1000);

    // even rainbow
    segmentArr[0] = { 0xff0000, 100, 100 };
    segmentArr[1] = { 0x00ff00, 100, 100 };
    segmentArr[2] = { 0x0000ff, 100, 100 };
    smoothRunners(runSec, 20, segmentArr, 3);
    clear(pixels.Color(0, 0, 0), 1000);

    // uneven rainbow
    segmentArr[0] = { 0xff0000, -100, 100 };
    segmentArr[1] = { 0x00ff00, -120, 100 };
    segmentArr[2] = { 0x0000ff, -140, 100 };
    smoothRunners(runSec, 20, segmentArr, 3);
    clear(pixels.Color(0, 0, 0), 1000);

    // darker rainbow
    segmentArr[0] = { 0xff0000, 60, 100 };
    segmentArr[1] = { 0x00ff00, 70, 100 };
    segmentArr[2] = { 0x0000ff, -80, 100 };
    smoothRunners(runSec, 20, segmentArr, 3);
    clear(pixels.Color(0, 0, 0), 1000);

    // shimmer 1
    segmentArr[0] = { 0xff0000, 123, 75 };
    segmentArr[1] = { 0x00ff00, 456, 75 };
    segmentArr[2] = { 0x0000ff, -789, 75 };
    smoothRunners(runSec, 1, segmentArr, 3);
    clear(pixels.Color(0, 0, 0), 1000);

    // shimmer 2
    segmentArr[0] = { 0xff0000, 1000, 75 };
    segmentArr[1] = { 0x00ff00, 2000, 75 };
    segmentArr[2] = { 0x0000ff, -1500, 75 };
    smoothRunners(runSec, 1, segmentArr, 3);
    clear(pixels.Color(0, 0, 0), 1000);

//    // tweaked for 16 pixel grid. darker rainbow
//    segmentArr[0] = { 0xff0000, 60, 70 };
//    segmentArr[1] = { 0x00ff00, 70, 70 };
//    segmentArr[2] = { 0x0000ff, -80, 70 };
//    smoothRunners(60*60, 20, segmentArr, 3);
//    clear(pixels.Color(0, 0, 0), 1000);

    // Show single colors
    clear(0xff0000, 3000);
    delay(1000);
    clear(0xffff00, 3000);
    delay(1000);
    clear(0x00ff00, 3000);
    delay(1000);
    clear(0x00ffff, 3000);
    delay(1000);
    clear(0x0000ff, 3000);
    delay(1000);
    clear(0xff00ff, 3000);
    delay(1000);
    clear(0xffffff, 3000);
    delay(1000);
    clear(0x000000, 3000);
}
Example #27
0
void ws2812_initialise() {
    // initialises the strip
    strip.begin();
    strip.show();
}
Example #28
0
void set_neopixel_color(const uint32_t color) {
  for (uint16_t i = 0; i < pixels.numPixels(); ++i)
    pixels.setPixelColor(i, color);
  pixels.show();
}
Example #29
0
void ExtendoHand::setColor(unsigned long color) {
    leds.setPixelColor(0, (uint32_t) color);
    leds.show();
}
Example #30
0
void setup(){
	Serial.begin(B2_SERIAL0_BOUND);
	serial0Buffer = "";
	Serial.println("");	// remove dust
	Serial.flush();

	// read pcb type	
	pinMode( PIN_B3_POWER_SENSOR, INPUT );
	boolean power = digitalRead( PIN_B3_POWER_SENSOR );
	if( power == LOW ){
		Serial.println("-chyba 2");
	}else{
		Serial.println("-chyba 3");
	}

	//pcb_type
	disableYZ();
	if(pcb_type == 2 ){		// servos + magicled
		//pinMode(PIN_B2_SERVO_Y, INPUT+INPUT_PULLUP );      // nie pozwalaj na przypadkowe machanie na starcie
		//pinMode(PIN_B2_SERVO_Z, INPUT+INPUT_PULLUP );      // nie pozwalaj na przypadkowe machanie na starcie
		pinMode(PIN_B2_SELF_RESET, INPUT );	
		pinMode(PIN_B2_HALL_X, INPUT + INPUT_PULLUP );
		pinMode(PIN_B2_HALL_Y, INPUT + INPUT_PULLUP );
		pinMode(PIN_B2_WEIGHT, INPUT);

	}else if(pcb_type == 3 ){		// actuators + magicled
		if(YZ_INPUT_ON_DISABLE){
			pinMode(PIN_B3_OUT_Y1, INPUT );		// stop Y
			pinMode(PIN_B3_OUT_Y2, INPUT );		// stop Y		
			pinMode(PIN_B3_OUT_Z1, INPUT );		// stop Z	
			pinMode(PIN_B3_OUT_Z2, INPUT );		// stop Z
		}else{
			pinMode(PIN_B3_OUT_Y1, OUTPUT);
			pinMode(PIN_B3_OUT_Y2, OUTPUT);
			pinMode(PIN_B3_OUT_Z1, OUTPUT);
			pinMode(PIN_B3_OUT_Z2, OUTPUT);
			pinMode(PIN_B3_LIGHT, INPUT );

			digitalWrite(PIN_B3_OUT_Y1, YZ_VALUE_ON_DISABLE);		// stop Y
			digitalWrite(PIN_B3_OUT_Y2, YZ_VALUE_ON_DISABLE);
			digitalWrite(PIN_B3_OUT_Z1, YZ_VALUE_ON_DISABLE);		// stop Z
			digitalWrite(PIN_B3_OUT_Z2, YZ_VALUE_ON_DISABLE);	

		}
		//pinMode(PIN_B3_POWER_SENSOR, INPUT + INPUT_PULLUP );
		pinMode(PIN_B3_POWER_SENSOR, INPUT );	
	}

	// blink led	
	pinMode(PIN_B2_STEPPER_DIR, OUTPUT );
	for(byte i =0; i<pcb_type;i++){
		digitalWrite( PIN_B2_STEPPER_DIR, HIGH );
		delay(100);
		digitalWrite( PIN_B2_STEPPER_DIR, LOW );
		delay(200);
	}
	init_leds();
	setupStepper();

	unsigned long int color = bottom_panels.Color(0,  0,  20 );	
	set_all_leds(color);
	Serial.println("");	// remove dust
	Serial.flush();
	Serial.println("BSTART");

	if(pcb_type == 2 ){		// servos + magicled
		init_hallx(PIN_B2_HALL_X);
	}else if(pcb_type == 3 ){
		init_hallx(PIN_B3_IN_X);
	}

	sendStats( true );
	Serial.flush();
}