コード例 #1
0
void flickerDim(uint16_t position) {
  if(chanceOneIn(50)){
    setLedColor(position, brighten8(getLedColor(position), 1));
  } else {
    setLedColor(position, dim256(getLedColor(position), 4));
  }
}
コード例 #2
0
ファイル: motors.c プロジェクト: NsTremblay/real-time2016
/**
 * \brief Change movement type
 * \detailed change the pulse width to allow the robot to move [forward, backward, stop, rotate left, rotate right]
 * \param movement_type - an integer value that indicates the type of movement to execute
 */
void setMovementType(uint8_t movement_type) {
	currentMovementType = movement_type;
	switch (movement_type) {
	case FORWARD_MOVEMENT:
		startWheelMovement();
		setLeftRightWheelPulses(leftForwardWidth, rightForwardWidth);
		setLedColor(GREEN);
		break;
	case BACKWARD_MOVEMENT:
		startWheelMovement();
		setLeftRightWheelPulses(leftBackwardWidth, rightBackwardWidth);
		setLedColor(RED);
		break;
	case ROTATE_LEFT_MOVEMENT:
		startWheelMovement();
		setLeftRightWheelPulses(leftBackwardWidth, rightForwardWidth);
		setLedColor(BLUE);
		break;
	case ROTATE_RIGHT_MOVEMENT:
		startWheelMovement();
		setLeftRightWheelPulses(leftForwardWidth, rightBackwardWidth);
		setLedColor(BLUE);
		break;
	default:
		stopWheelMovement();
		setLedColor(WHITE);
	}
}
コード例 #3
0
void movePixel(int position, int moveBy) {
  int targetPosition = position + moveBy;

  if(targetPosition >= 0 && targetPosition < NUM_LEDS) {
    setLedColor(targetPosition, getLedColor(position));
  }

  setLedColor(position, BLACK);
}
コード例 #4
0
uint16_t twinkleTwinkle(uint16_t tick, uint32_t color, uint8_t cycles) {
  for (uint16_t i=0; i<NUM_LEDS; i++) {
    if(getLedColor(i) > BLACK) {
      setLedColor(i, dim256(getLedColor(i), map(cycles, NUM_CYCLES, 0, 10, 100)));
    } else if (chanceOneIn(map(cycles, NUM_CYCLES, 0, 500, 10))) {
      setLedColor(i, getRandomColor());
    }
  }

  return 1;
}
コード例 #5
0
uint16_t dimRider(uint16_t tick, uint32_t color) {
  uint8_t dimBy;
  for (uint16_t i=0; i<NUM_LEDS; i++) {
    setLedColor(i, BLACK);
  }
  if(tick < NUM_LEDS / 2) {
    dimBy = map(tick, 0, NUM_LEDS/2, 255, 0);
  } else {
    dimBy = map(NUM_LEDS - tick, 0, NUM_LEDS/2, 255, 0);
  }
  setLedColor(tick, dim256(color, dimBy));
  return NUM_LEDS;
}
コード例 #6
0
uint16_t knightRider(uint16_t tick, uint32_t color) {
  for (uint16_t i=0; i<NUM_LEDS; i++) {
    setLedColor(i, BLACK);
  }

  if (tick < NUM_LEDS) {
    setLedColor(tick, color);
  } else {
    setLedColor(NUM_LEDS-(2+tick-NUM_LEDS), color);
  }

  return 2*NUM_LEDS-2;
}
コード例 #7
0
uint16_t snake1(uint16_t tick, uint32_t color, uint16_t length, uint16_t increment) {
  uint16_t offset = (tick % length) * increment;

  for (uint16_t i = 0; i<NUM_LEDS; i++) {
    if (0==((offset+i)%length)) {
      setLedColor(i, color);
    } else {
      setLedColor(i, BLACK);
    }
  }

  return length;
}
コード例 #8
0
uint16_t competitivePixels(uint16_t tick, uint32_t color) {
  uint8_t speed;

  for (uint16_t i=0; i<NUM_LEDS; i++) {
    if(getLedColor(i) > BLACK) {
      speed = getLedColor(i) % 5;
      setLedColor(i + speed, getLedColor(i));
      setLedColor(i, BLACK);
      i = i + speed;
    } else if(i == 0 && chanceOneIn(100)) {
      setLedColor(i, getRandomColor());
    }
  }

  return 1;
}
コード例 #9
0
uint16_t staticColor(uint16_t tick, uint32_t color) {
  for (uint16_t i = 0; i<NUM_LEDS; i++) {
    setLedColor(i, color);
  }

  return 1;
}
コード例 #10
0
uint16_t rainbow(uint16_t tick, uint32_t color) {

  for (uint16_t i=0; i<NUM_LEDS; i++) {
    setLedColor(i, rainbowColor(i+tick, NUM_LEDS));
  }

  return NUM_LEDS;
}
コード例 #11
0
uint16_t wave4(uint16_t tick, uint32_t color, boolean forward) {
  uint16_t offset;

  if (forward) {
    offset = tick;
  } else {
    offset = 3-tick;
  }
  for (uint16_t i = 0; i<NUM_LEDS; i++) {
    switch ((i+offset) % 4) {
      case 0: setLedColor(i, dim8(color, 8));   break;
      case 1: // fall through
      case 3: setLedColor(i, dim8(color, 4));   break;
      case 2: setLedColor(i, color);           break;
    }
  }

  return 4;
}
コード例 #12
0
ファイル: demo.cpp プロジェクト: Jeniffere/LedMatrixDriver
void flashMatrixBuffer(int red, int green, int blue)
{
	for(int row=0;row<8;row++)
	{
		for(int colom=0;colom<8;colom++)
		{
			MatrixBuffer_01[row][colom] = setLedColor(red, green, blue);
		}
	}
}
コード例 #13
0
uint16_t yourAnimation(uint16_t tick, uint32_t color) {
  // Edit away or copy it to make your own.
  // The resulting animation looks the same as "snake1ToAllForward"

  for (uint16_t i = 0; i<NUM_LEDS; i++) {
  // go through the entire strip of LEDs and set each one
    if(i == tick) {
      // set the led with the index of the current "tick"/step to color
      setLedColor(i, color);
    } else {
      // Set all other LEDs to black / OFF
      // Without this, the LEDs from the previous tick would remain on and the entire strip would will up.
      setLedColor(i, BLACK);
    }
  }

  // The number of "frames" of the animation.
  // Since the dot is supposed to go through every single LED of the strip, the animation length is the number of LEDs that the strip has. This number is defined in the constant NUM_LEDS.
  // "tick" increments from 0 to this value.
  return NUM_LEDS;
}
コード例 #14
0
ファイル: demo.cpp プロジェクト: Jeniffere/LedMatrixDriver
void clearMatrixBuffer()
{
	if(activeBuffer == 1)
	{
		for(int row=0;row<8;row++)
		{
			for(int colom=0;colom<8;colom++)
			{	
				MatrixBuffer_01[row][colom] = setLedColor(0x00, 0x00, 0x00);
			}
		}
	}
	else
	{
		for(int row=0;row<8;row++)
		{
			for(int colom=0;colom<8;colom++)
			{	
				MatrixBuffer_02[row][colom] = setLedColor(0x00, 0x00, 0x00);
			}
		}
	}
}
コード例 #15
0
uint16_t saw(uint16_t tick, uint32_t color, uint16_t length, boolean forward) {
  uint16_t level;

  for (uint16_t i=0; i<NUM_LEDS; i++) {
    if (forward) {
      level = ((tick+i)%length) * (8/length);
    } else {
      level = ((tick+(length-i))%length) * (8/length);
    }
    setLedColor(i, dim8(color, level));
  }

  return length;
}
コード例 #16
0
uint16_t wave8(uint16_t tick, uint32_t color, boolean forward) {
  uint16_t offset;

  if (forward) {
    offset = tick;
  } else {
    offset = 7-tick;
  }
  for (uint16_t i = 0; i<NUM_LEDS; i++) {
    switch ((i+offset) % 8) {
      case 0: setLedColor(i, dim8(color, 8));   break;
      case 1: // fall through
      case 7: setLedColor(i, dim8(color, 6));   break;
      case 2: // fall through
      case 6: setLedColor(i, dim8(color, 4));   break;
      case 3: // fall through
      case 5: setLedColor(i, dim8(color, 2));   break;
      case 4: setLedColor(i, color);           break;
    }
  }

  return 8;
}
コード例 #17
0
uint16_t tinyExplosions(uint16_t tick, uint32_t color) {

  for (uint16_t i=0; i<NUM_LEDS; i++) {
    if (isDimmedMagenta(getLedColor(i))) {
      flickerDim(i);
    }
  }

  drawAllCollisions();
  moveAllPixelsForward(RED);
  drawAllCollisions();
  moveAllPixelsBackward(BLUE);

  // put in new pixels at the end of the strip
  if(chanceOneIn(300)) {
    setLedColor(0, RED);
  }

  if(chanceOneIn(300)) {
    setLedColor(NUM_LEDS-1, BLUE);
  }

  return 1;
}
コード例 #18
0
uint16_t blinkColor(uint16_t tick, uint32_t color) {
  uint32_t _color;

  if (tick == 0) {
    _color = color;
  } else {
    _color = BLACK;
  }

  for (uint16_t i = 0; i<NUM_LEDS; i++) {
    setLedColor(i, _color);
  }

  return 2;
}
コード例 #19
0
uint16_t breathe(uint16_t tick, uint32_t color) {
  uint8_t dimBy;
  if(tick < 32) {
    dimBy = tick;
  } else {
    dimBy = 64 - tick;
  }
  if(dimBy >= 256) {
    dimBy = 255;
  }
  for (uint16_t i=0; i<NUM_LEDS; i++) {
      setLedColor(i, dim8(color, dimBy * 8));
  }

  return 64;
}
コード例 #20
0
ファイル: demo.cpp プロジェクト: Jeniffere/LedMatrixDriver
int main()
{
	printf("Hello Word!\n");
	MatrixBuffer_01[0][0] = setLedColor(1,4,3);
	printf("%d\n", MatrixBuffer_01[0][0].red);
	printf("%d\n", MatrixBuffer_01[0][0].green);
	printf("%d\n", MatrixBuffer_01[0][0].blue);
	clearMatrixBuffer();
	printf("%d\n", MatrixBuffer_01[0][0].red);
	printf("%d\n", MatrixBuffer_01[0][0].green);
	printf("%d\n", MatrixBuffer_01[0][0].blue);
	flashMatrixBuffer(5,4,3);
	printf("%d\n", MatrixBuffer_01[0][0].red);
	printf("%d\n", MatrixBuffer_01[0][0].green);
	printf("%d\n", MatrixBuffer_01[0][0].blue);
	return 0;
}
コード例 #21
0
ファイル: main.c プロジェクト: johannes85/bloenk-hardware
int __attribute__((noreturn)) main(void)
{
	uchar   i;

	// Read oscillator calibration
	uchar   calibrationValue;
	calibrationValue = eeprom_read_byte(&eeCalibrationMemory); /* calibration value from last time */
    if(calibrationValue != 0xff){
        OSCCAL = calibrationValue;
    }
	
    wdt_enable(WDTO_1S);
	
	// Init USB
    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i){             /* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
    sei();
	
	// Read led count configuration
	ledCount = eeprom_read_byte(&eeLedCountMemory);
	if(ledCount == 0xff){
		ledCount = LED_DEFAULT_COUNT;
	}
	
	// Init leds
	currentLed = 0;
	LED_PORT_DDR |= 1 << LED_BIT;
	for (i=0; i<ledCount; i++) {
		setLedColor(i, 0, 30, 0);
	}
	writeToLeds();
	
	// Main loop
    for(;;){
        wdt_reset();
        usbPoll();
    }
}
コード例 #22
0
uint16_t fire2012(uint16_t tick, uint32_t color) {
  // Fire2012 by Mark Kriegsman, July 2012
  // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
  // adapted from example included with fastLED
  if(tick == 0) {
    random16_add_entropy( random());

    static byte heat[NUM_LEDS];

    // Array of temperature readings at each simulation cell
    // Step 1.  Cool down every cell a little
    for( int i = 0; i < NUM_LEDS; i++) {
      heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
    }

    // Step 2.  Heat from each cell drifts 'up' and diffuses a little
    for( int k= NUM_LEDS - 1; k >= 2; k--) {
      heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
    }

    // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
    if( random8() < SPARKING) {
      int y = random8(7);
      heat[y] = qadd8( heat[y], random8(160,255) );
    }

    // Step 4.  Map from heat cells to LED colors
    for(uint16_t j = 0; j < NUM_LEDS; j++) {
      CRGB hColor = HeatColor(heat[j]);
      uint32_t red    = hColor.red;
      uint32_t green  = hColor.green;
      uint32_t blue   = hColor.blue;

      uint32_t intColor = (red<<16)+(green<<8)+blue;
      setLedColor(j, HeatColor(heat[j]));
    }
  }
  return 4;
}
コード例 #23
0
void drawExplosion(uint16_t position) {
  setLedColor(position, MAGENTA);
}