void rgblight_set(void) { LED_TYPE *start_led = led + clipping_start_pos; uint16_t num_leds = clipping_num_leds; if (rgblight_config.enable) { #ifdef RGBLIGHT_LED_MAP LED_TYPE led0[RGBLED_NUM]; for(uint8_t i = 0; i < RGBLED_NUM; i++) { led0[i] = led[pgm_read_byte(&led_map[i])]; } start_led = led0 + clipping_start_pos; #endif #ifdef RGBW ws2812_setleds_rgbw(start_led, num_leds); #else ws2812_setleds(start_led, num_leds); #endif } else { for (uint8_t i = 0; i < RGBLED_NUM; i++) { led[i].r = 0; led[i].g = 0; led[i].b = 0; } #ifdef RGBW ws2812_setleds_rgbw(start_led, num_leds); #else ws2812_setleds(start_led, num_leds); #endif } }
uchar usbFunctionSetup(uchar data[8]) { usbRequest_t *rq = (void *)data; switch (rq->bRequest) { case 0: target[0].r=rq->wValue.bytes[0]; target[0].g=rq->wValue.bytes[1]; target[0].b=rq->wValue.bytes[2]; ws2812_setleds(&target, 2); break; case 1: ws2812_setleds(&target, 2); _delay_ms(rq->wValue.word); ws2812_setleds(¤t, 2); break; case 2: { usbMsgPtr = iobuf; return 8; } case 3: return USB_NO_MSG; } return 0; }
void * matrix_scan_user(void) { uint8_t layer = biton32(layer_state); switch (layer) { case 1: led[15].r = 255; led[15].g = 0; led[15].b = 0; ws2812_setleds(led, 16); break; case 2: led[15].r = 0; led[15].g = 255; led[15].b = 0; ws2812_setleds(led, 16); break; case 3: led[15].r = 0; led[15].g = 0; led[15].b = 255; ws2812_setleds(led, 16); break; default: led[15].r = 0; led[15].g = 0; led[15].b = 0; ws2812_setleds(led, 16); break; } };
int main(void) { uint8_t i; struct pixel p = {255, 0, 0}; /* loop */ while (1) { if (p.r > 0 && p.b == 0) { p.r--; p.g++; } if (p.g > 0 && p.r == 0) { p.g--; p.b++; } if (p.b > 0 && p.g == 0) { p.r++; p.b--; } for (i = 0; i < PIXEL_NUM; ++i) { pixels[i] = p; } ws2812_setleds((struct cRGB *)pixels, PIXEL_NUM); _delay_ms(10); } }
int main( ) { DDRC |= ( 1<<PC5 ); PORTC |= ( 1<<PC5 ); DDRC |= (1<<PC2); // TEST LED PORTC |= (1<<PC2); spi_slave_init(); sei(); uint8_t* data; while ( 1 ) { //data != NULL if there is data in the SPI-buffer data = spi_receive( ); if ( data ) { //Disable interrupts for more performance cli(); //Write received data to the ledstrip //Technically this function wants a RGB-struct but casts it internal to an uint8 array. //So we simply ignore the struct to make it easier for us and to save RAM on the ATmega. ws2812_setleds( data, NUM_LEDS ); //Enable interrupts again sei(); //Set ready to receive to get data PORTC |= ( 1<<PC5 ); PORTC |= (1<<PC2); } } }
void lauflicht(void) { PORTC &= ~(1 << 1); uint8_t i = 0; uint8_t j = 37; uint8_t k = 73; while (1) { matrix[i].r = 30; matrix[j].g = 30; matrix[k].b = 30; ws2812_setleds(matrix, 110); matrix[i].r = 0; matrix[j].g = 0; matrix[k].b = 0; i++; j++; k++; if (i >= 110) { i = 0; } if (j >= 110) { j = 0; } if (k >= 110) { k = 0; } _delay_ms(100); } }
void leds_off() { struct cRGB color = {0, 0, 0}; for (int i = 0; i < leds_count; i++) { leds_set(i, color); } ws2812_setleds(leds, leds_count); }
void rgblight_set(void) { if (rgblight_config.enable) { #ifdef RGBW ws2812_setleds_rgbw(led, RGBLED_NUM); #else ws2812_setleds(led, RGBLED_NUM); #endif } else { for (uint8_t i = 0; i < RGBLED_NUM; i++) { led[i].r = 0; led[i].g = 0; led[i].b = 0; } #ifdef RGBW ws2812_setleds_rgbw(led, RGBLED_NUM); #else ws2812_setleds(led, RGBLED_NUM); #endif } }
int main(void) { #ifdef __AVR_ATtiny10__ CCP=0xD8; // configuration change protection, write signature CLKPSR=0; // set cpu clock prescaler =1 (8Mhz) (attiny 4/5/9/10) #else CLKPR=_BV(CLKPCE); CLKPR=0; // set clock prescaler to 1 (attiny 25/45/85/24/44/84/13/13A) #endif while(1) { // Red to Red+Blue to Blue for (r = MAXCOLOR, b = MINCOLOR; b < MAXCOLOR; r -= COLSTEP, b += COLSTEP) { led[0].r = r; led[0].g = 0; led[0].b = b; ws2812_setleds(led, 1); _delay_ms(DELAY); } // Blue to Blue+Green to Green for (b = MAXCOLOR, g = MINCOLOR; g < MAXCOLOR; b -= COLSTEP, g += COLSTEP) { led[0].r = 0; led[0].g = g; led[0].b = b; ws2812_setleds(led, 1); _delay_ms(DELAY); } // Green to Red+Green to Red for (g = MAXCOLOR, r = MINCOLOR; r < MAXCOLOR; g -= COLSTEP, r += COLSTEP) { led[0].r = r; led[0].g = g; led[0].b = 0; ws2812_setleds(led, 1); _delay_ms(DELAY); } } }
inline void bounceRender() { memset(bouncePixBuf, 0, sizeof(unsigned char) * NUM_LEDS); bounceRenderBouncer(truePosition); if (hasReflection) bounceRenderBouncer(reflectionPosition); memset(frameBuffer, 0, sizeof(struct cRGB) * NUM_LEDS); for (int i = 0; i < NUM_LEDS; i++) { frameBuffer[i] = hsvToRgbInt3(bounceHue, MAX_SAT, bouncePixBuf[i]); } ws2812_setleds(frameBuffer, NUM_LEDS); // Blocks for ~0.7ms }
void led_init() { // set D6 low, turn off led // DDRD |= (1<<6); // PORTD &= ~(1<<6); // // set C7 as output // DDRC |= (1<<7); // set D4 as output DDRD |= (1<<4); // drive red led[0].r=50;led[0].g=0;led[0].b=0; // drive green // led[1].r=0;led[1].g=0;led[1].b=50; ws2812_setleds(led,1); }
void all_on(uint8_t prozent_rot, uint8_t prozent_blau, uint8_t prozent_gruen) { PORTC &= ~(1 << 1); while (0) { for (uint8_t i = 0; i <= 110; i++) { matrix[i].r = prozent_rot; matrix[i].g = prozent_gruen; matrix[i].b = prozent_blau; } ws2812_setleds(matrix, 110); _delay_ms(1000); _delay_ms(1000); _delay_ms(1000); _delay_ms(1000); _delay_ms(1000); } }
void showColor(unsigned char red, unsigned char green, unsigned char blue) { #ifdef __AVR_ATtiny10__ CCP=0xD8; // configuration change protection, write signature CLKPSR=0; // set cpu clock prescaler =1 (8Mhz) (attiny 4/5/9/10) #else CLKPR=_BV(CLKPCE); CLKPR=0; // set clock prescaler to 1 (attiny 25/45/85/24/44/84/13/13A) #endif int i; mRed = red; mGreen = green; mBlue = blue; for(i=0;i<=LED_COUNT;i++) { led[i].r=red; led[i].g=green; led[i].b=blue; } ws2812_setleds(led,LED_COUNT); }
void rgblight_set(void) { if (!rgblight_config.enable) { for (uint8_t i = 0; i < RGBLED_NUM; i++) { if (i == RGBLIGHT_FLED1 && i == RGBLIGHT_FLED2) continue; led[i].r = 0; led[i].g = 0; led[i].b = 0; } } switch (fled_mode) { case FLED_OFF: setrgb(0, 0, 0, &led[RGBLIGHT_FLED1]); setrgb(0, 0, 0, &led[RGBLIGHT_FLED2]); break; case FLED_INDI: copyrgb(&fleds[0], &led[RGBLIGHT_FLED1]); copyrgb(&fleds[1], &led[RGBLIGHT_FLED2]); break; case FLED_RGB: if (fled_hs[0].hue == 0 && fled_hs[0].hue == 0 && (rgblight_config.mode >= 15 && rgblight_config.mode <= 23)) setrgb(0, 0, 0, &led[RGBLIGHT_FLED1]); else sethsv(fled_hs[0].hue, fled_hs[0].sat, fled_val, &led[RGBLIGHT_FLED1]); if (fled_hs[1].hue == 0 && fled_hs[1].hue == 0 && (rgblight_config.mode >= 15 && rgblight_config.mode <= 23)) setrgb(0, 0, 0, &led[RGBLIGHT_FLED2]); else sethsv(fled_hs[1].hue, fled_hs[1].sat, fled_val, &led[RGBLIGHT_FLED2]); break; default: break; } ws2812_setleds(led, RGBLED_NUM); }
void init(void) { //in outputs intit //minutenleds + alarmLed //setze bit 1 =Ausgang DDRB |= (1 << 1); DDRB |= (1 << 3); DDRB |= (1 << 4); DDRB |= (1 << 5); DDRC |= (1 << 3); //AlarmLED // setze pin auf vdd = LED aus PORTB |= (1 << 1); PORTB |= (1 << 3); PORTB |= (1 << 4); PORTB |= (1 << 5); PORTC |= (1 << 3); //AlarmLED //Buzzer als Ausgang setzen und auf +5V schalten = ausgeschaltet DDRB |= (1 << 2); PORTB |= (1 << 2); //Mosfet als Ausgang und ausschalten DDRC |= (1 << 1); PORTC |= (1 << 1); //Matrix leeren PORTC &= ~(1 << 1); //Mosfet anschalten for (uint8_t i = 0; i <= 111; i++) { matrix[i].r = 0; matrix[i].g = 0;//TODO: evtl den gesamten BLock nach vorne verschieben matrix[i].b = 0; //War geplant damit am anfang erst einmal dunkel } ws2812_setleds(matrix, 111); PORTC |= (1 << 1); //init ds1307 ds1307_init(); }
void rgbsps_send(void) { ws2812_setleds(led, RGBSPS_NUM); }
void showtime(uint8_t hours_to_show, uint8_t minutes_to_show) { //beginn der Frontplattenansteuerung if(frontplatte==0) { //Zeitanzeige fŸr Standart Frontplatte //Minutenleds PORTB |= (1<<PB5); PORTB |= (1<<PB4); PORTB |= (1<<PB3); PORTB |= (1<<PB1);//alle Minutenleds off switch(minutes_to_show%5) {//setzen entsprechende Minuten auf GND case 1: PORTB &=~ (1<<PB4); break; case 2: PORTB &=~ (1<<PB4)^(1<<PB3); break; case 3: PORTB &=~ (1<<PB4)^(1<<PB3)^(1<<PB1); break; case 4: PORTB &=~ (1<<PB4)^(1<<PB3)^(1<<PB1)^(1<<PB5); break; } /* //Leeren des Arrays for(uint8_t i=0; i<=110; i++){ matrix[i].r=0;matrix[i].g=0;matrix[i].b=0; } //Ansteuerung der Matrix Vorlage: es ist ein uhr es ist fŸnf nach eins es ist zehn nach eins es ist viertel zwei es ist zehn vor halb zwei es ist fŸnf vor halb zwei es ist halb zwei es ist fŸnf nach halb zwei es ist zehn nach halb zwei es ist dreiviertel zwei es ist zehn vor zwei es ist fŸnf vor zwei */ //ES IST anschalten matrix[0].r=V_ON_R; matrix[0].g=V_ON_G; matrix[0].b=V_ON_B; matrix[1].r=V_ON_R; matrix[1].g=V_ON_G; matrix[1].b=V_ON_B; matrix[3].r=V_ON_R; matrix[3].g=V_ON_G; matrix[3].b=V_ON_B; matrix[4].r=V_ON_R; matrix[4].g=V_ON_G; matrix[4].b=V_ON_B;//TODO: ES IST darf nur dann angezeigt werden wenn es das auch soll matrix[5].r=V_ON_R; matrix[5].g=V_ON_G; matrix[5].b=V_ON_B; //TODO: Anpassen an die aktuellen Ports //Minuten anschalten /* switch(((int) (minutes_to_show/5))*5) { case 0:PORTD|= (1<<7) ; break; //x Uhr case 5:PORTB|= (1<<1);PORTB|= (1<<7); break; //5 nach x case 10:PORTB|= (1<<3);PORTB|= (1<<7) ; break; //10 nach x case 15:PORTB|= (1<<6); hours_to_show++ ; break; //viertel x+1 case 20:PORTB|= (1<<3); PORTA|= (1<<0); PORTA|= (1<<1);hours_to_show++ ; break; //zehn vor halb x+1 case 25:PORTB|= (1<<1); PORTA|= (1<<0); PORTA|= (1<<1);hours_to_show++ ; break; //fünf vor halb x+1 case 30:PORTA|= (1<<1);hours_to_show++ ; break; //halb x+1 case 35:PORTB|= (1<<1); PORTB|= (1<<7); PORTA|= (1<<1);hours_to_show++ ; break; //fŸnf nach halb x+1 case 40:PORTB|= (1<<3); PORTB|= (1<<7); PORTA|= (1<<1);hours_to_show++ ; break; //fŸnf nach halb x+1 case 45:PORTB|= (1<<5); PORTB|= (1<<6);hours_to_show++ ; break; //dreiviertel x+1 case 50:PORTB|= (1<<3); PORTA|= (1<<0);hours_to_show++ ; break; //zehn vor x+1 case 55:PORTB|= (1<<1); PORTA|= (1<<0);hours_to_show++ ; break; //fŸnf vor x+1 } if (hours_to_show>=13){hours_to_show=1;} switch (hours_to_show){ case 1: PORTA|= (1<<4);PORTA|= (1<<5);PORTA|= (1<<6);break; //EINS case 2: PORTA|= (1<<3);PORTA|= (1<<4);break; //ZWEI case 3: PORTC|= (1<<7);break; //DREI case 4: PORTC|= (1<<3);break; //VIER case 5: PORTC|= (1<<6);break; //F†NF case 6: PORTC|= (1<<0);break; //SECHS case 7: PORTA|= (1<<6);PORTA|= (1<<7);break; //SIEBEN case 8: PORTC|= (1<<2);break; //ACHT case 9: PORTC|= (1<<4);break; //NEUN case 10: PORTC|= (1<<1);break; //ZEHN case 11: PORTC|= (1<<5);break; //ELF case 12: PORTA|= (1<<2);break; //ZW…LF } */ } else if(frontplatte==1) { //Zeitanzeige fŸr BinŠre Frontplatte } else if(frontplatte==2) { //Zeitanzeige fŸr Englische Frontplatte } //Ende der Frontplattenansteuerung if(matrix_on) { PORTC &= ~ (1<<1); //TODO:Mosfet anschalten ws2812_setleds(matrix,10); } else { //TODO:Mosfet ausschalten } }
int main(void) { uint8_t i, j; struct cRGB leds[NUM_MODULES] = {{ 0 }}; /* struct cRGB my_color = { */ /* .r = 0x68, */ /* .g = 0x28, */ /* .b = 0x00 */ /* }; */ wdt_reset(); cli(); PRR = _BV(PRADC); DDRB = _BV(DO_ONEWIRE) | _BV(PB0); DDRC = _BV(DO_MCOM) | IRSEL_MASK; DDRD = MSEL_MASK | _BV(PD5) | _BV(PD7); PORTB = _BV(PB2); PORTB = 0; PORTC = 0; PORTD = _BV(PD5); // CTC, /256 divider for 640 µs tick // The transmission starts with 24 alternating edges about 630 µs apart. // Since the pulse period is closely matched to the tick period, we are // basically guaranteed at least one edge to lock onto in every tick // period, most likely two. // Since we are sending more edges than we need (12 pulses but only 8 // sensor modules total) we are also guaranteed that we can lock onto the // signal within one full cycle when not already busy for more than half of // a message time. // After that the state machine can suck in the data, ignoring any leading pulses. TCCR0A = _BV(WGM01); TCCR0B = _BV(CS02); TIMSK0 = _BV(OCIE0A); OCR0A = 0x13; // same 38 KHz timer as transmitter for timing pulses TCCR1A = _BV(WGM11); TCCR1B = _BV(WGM13) | _BV(CS10); TIMSK1 = _BV(TOIE1); ICR1 = 0x0068; OCR1A = 0x0046; // pin change interrupt on PCINT22 (PD6) to detect incoming IR data edges PCICR = _BV(PCIE2); PCMSK2 = _BV(PCINT22); timer_init(timers, 1); PORTD &= ~_BV(PD5); sei(); for (i = 0; i < NUM_MODULES; i++) { for (j = 0; j < NUM_MODULES; j++) { if (j <= i) { leds[j].r = 0xFF; } else { leds[j].r = 0x00; } } ws2812_setleds(leds, NUM_MODULES); _delay_ms(50); } _delay_ms(300); for (i = 0xFF; i > 0; i--) { for (j = 0; j < NUM_MODULES; j++) { leds[j].r = i - 1; } ws2812_setleds(leds, NUM_MODULES); _delay_ms(1); } //timer_arm(&timers[1], 1000); for (;;) { if (bit_is_set(TFLAG, TRECVTIMEOUT)) { cli(); TFLAG &= ~_BV(TRECVTIMEOUT); //aaaaaa = 0; PRR &= ~_BV(PRTIM0); set_state(STATE_WAIT); sei(); } if (do_pulse) { //uint8_t sreg = SREG; //cli(); do_pulse = 0; //msel = motor_map[trigger_sel]; //SREG = sreg; if (data_byte == 0x1B) { pulse_led(leds, NUM_MODULES, led_map[trigger_sel], 20, 255, 160); }/* else { pulse_led(leds, NUM_MODULES, ledsel, (struct cRGB*)&cc); }*/ // select corresponding motor //PORTD = (PORTD & ~MSEL_MASK) | ((msel << 2) & MSEL_MASK); //PORTC |= _BV(DO_MCOM); //_delay_ms(800); //PORTC &= ~_BV(DO_MCOM); } /* if (do_test) { do_test = 0; for (i = 0; i < 3; i++) { leds[i].r = 0; leds[i].g = 0; leds[i].b = 0xFF; } ws2812_setleds(leds, 3); _delay_ms(20); for (i = 0; i < 3; i++) { leds[i].r = 0; leds[i].g = 0; leds[i].b = 0; } ws2812_setleds(leds, 3); timer_arm(&timers[1], 1000); } */ } return 0; }
void leds_set(int id, struct cRGB rgb) { leds[id] = rgb; ws2812_setleds(leds, leds_count); }
void showtime(uint8_t hours_to_show, uint8_t minutes_to_show) { //beginn der Frontplattenansteuerung if (frontplatte == 0) { //Zeitanzeige fŸr Standart Frontplatte //Minutenleds PORTB |= (1 << PB5); PORTB |= (1 << PB4); PORTB |= (1 << PB3); PORTB |= (1 << PB1); //alle Minutenleds off switch (minutes_to_show % 5) { //setzen entsprechende Minuten auf GND = anschalten case 1: PORTB &= ~(1 << PB4); break; case 2: PORTB &= ~(1 << PB4) ^ (1 << PB3); break; case 3: PORTB &= ~(1 << PB4) ^ (1 << PB3) ^ (1 << PB1); break; case 4: PORTB &= ~(1 << PB4) ^ (1 << PB3) ^ (1 << PB1) ^ (1 << PB5); break; } //Leeren des Arrays for (uint8_t i = 0; i < 111; i++) { matrix[i].r = 0; matrix[i].g = 0; matrix[i].b = 0; } PORTC &= ~(1 << 1); //Mosfet anschalten ws2812_setleds(matrix, 111); /* //Ansteuerung der Matrix Vorlage: es ist ein uhr es ist fŸnf nach eins es ist zehn nach eins es ist viertel zwei es ist zehn vor halb zwei es ist fŸnf vor halb zwei es ist halb zwei es ist fŸnf nach halb zwei es ist zehn nach halb zwei es ist dreiviertel zwei es ist zehn vor zwei es ist fŸnf vor zwei */ //ES IST anschalten matrix[0].r = V_ON_R; matrix[0].g = V_ON_G; matrix[0].b = V_ON_B; matrix[1].r = V_ON_R; matrix[1].g = V_ON_G; matrix[1].b = V_ON_B; matrix[3].r = V_ON_R; matrix[3].g = V_ON_G; matrix[3].b = V_ON_B; matrix[4].r = V_ON_R; matrix[4].g = V_ON_G; matrix[4].b = V_ON_B;//TODO: ES IST darf nur dann angezeigt werden wenn es das auch soll matrix[5].r = V_ON_R; matrix[5].g = V_ON_G; matrix[5].b = V_ON_B; //TODO: Anpassen an die aktuellen Ports //Minuten anschalten switch (((int) (minutes_to_show / 5)) * 5) { case 0: //x Uhr matrix[107].r = V_ON_R; matrix[107].g = V_ON_G; matrix[107].b = V_ON_B; matrix[108].r = V_ON_R; matrix[108].g = V_ON_G; matrix[108].b = V_ON_B; matrix[109].r = V_ON_R; matrix[109].g = V_ON_G; matrix[109].b = V_ON_B; break; case 5: //5 nach x matrix[7].r = V_ON_R; matrix[7].g = V_ON_G; matrix[7].b = V_ON_B; matrix[8].r = V_ON_R; matrix[8].g = V_ON_G; matrix[8].b = V_ON_B; matrix[9].r = V_ON_R; matrix[9].g = V_ON_G; matrix[9].b = V_ON_B; matrix[10].r = V_ON_R; matrix[10].g = V_ON_G; matrix[10].b = V_ON_B; matrix[40].r = V_ON_R; matrix[40].g = V_ON_G; matrix[40].b = V_ON_B; matrix[41].r = V_ON_R; matrix[41].g = V_ON_G; matrix[41].b = V_ON_B; matrix[42].r = V_ON_R; matrix[42].g = V_ON_G; matrix[42].b = V_ON_B; matrix[43].r = V_ON_R; matrix[43].g = V_ON_G; matrix[43].b = V_ON_B; break; case 10: //10 nach x matrix[11].r = V_ON_R; matrix[11].g = V_ON_G; matrix[11].b = V_ON_B; matrix[12].r = V_ON_R; matrix[12].g = V_ON_G; matrix[12].b = V_ON_B; matrix[13].r = V_ON_R; matrix[13].g = V_ON_G; matrix[13].b = V_ON_B; matrix[14].r = V_ON_R; matrix[14].g = V_ON_G; matrix[14].b = V_ON_B; matrix[40].r = V_ON_R; matrix[40].g = V_ON_G; matrix[40].b = V_ON_B; matrix[41].r = V_ON_R; matrix[41].g = V_ON_G; matrix[41].b = V_ON_B; matrix[42].r = V_ON_R; matrix[42].g = V_ON_G; matrix[42].b = V_ON_B; matrix[43].r = V_ON_R; matrix[43].g = V_ON_G; matrix[43].b = V_ON_B; break; case 15: //viertel x+1 matrix[26].r = V_ON_R; matrix[26].g = V_ON_G; matrix[26].b = V_ON_B; matrix[27].r = V_ON_R; matrix[27].g = V_ON_G; matrix[27].b = V_ON_B; matrix[28].r = V_ON_R; matrix[28].g = V_ON_G; matrix[28].b = V_ON_B; matrix[29].r = V_ON_R; matrix[29].g = V_ON_G; matrix[29].b = V_ON_B; matrix[30].r = V_ON_R; matrix[30].g = V_ON_G; matrix[30].b = V_ON_B; matrix[31].r = V_ON_R; matrix[31].g = V_ON_G; matrix[31].b = V_ON_B; hours_to_show++; break; case 20: //zehn vor halb x+1 matrix[11].r = V_ON_R; matrix[11].g = V_ON_G; matrix[11].b = V_ON_B; matrix[12].r = V_ON_R; matrix[12].g = V_ON_G; matrix[12].b = V_ON_B; matrix[13].r = V_ON_R; matrix[13].g = V_ON_G; matrix[13].b = V_ON_B; matrix[14].r = V_ON_R; matrix[14].g = V_ON_G; matrix[14].b = V_ON_B; matrix[33].r = V_ON_R; matrix[33].g = V_ON_G; matrix[33].b = V_ON_B; matrix[34].r = V_ON_R; matrix[34].g = V_ON_G; matrix[34].b = V_ON_B; matrix[35].r = V_ON_R; matrix[35].g = V_ON_G; matrix[35].b = V_ON_B; matrix[44].r = V_ON_R; matrix[44].g = V_ON_G; matrix[44].b = V_ON_B; matrix[45].r = V_ON_R; matrix[45].g = V_ON_G; matrix[45].b = V_ON_B; matrix[46].r = V_ON_R; matrix[46].g = V_ON_G; matrix[46].b = V_ON_B; matrix[47].r = V_ON_R; matrix[47].g = V_ON_G; matrix[47].b = V_ON_B; hours_to_show++; break; case 25: //fŸnf vor halb x+1 matrix[7].r = V_ON_R; matrix[7].g = V_ON_G; matrix[7].b = V_ON_B; matrix[8].r = V_ON_R; matrix[8].g = V_ON_G; matrix[8].b = V_ON_B; matrix[9].r = V_ON_R; matrix[9].g = V_ON_G; matrix[9].b = V_ON_B; matrix[10].r = V_ON_R; matrix[10].g = V_ON_G; matrix[10].b = V_ON_B; matrix[33].r = V_ON_R; matrix[33].g = V_ON_G; matrix[33].b = V_ON_B; matrix[34].r = V_ON_R; matrix[34].g = V_ON_G; matrix[34].b = V_ON_B; matrix[35].r = V_ON_R; matrix[35].g = V_ON_G; matrix[35].b = V_ON_B; matrix[44].r = V_ON_R; matrix[44].g = V_ON_G; matrix[44].b = V_ON_B; matrix[45].r = V_ON_R; matrix[45].g = V_ON_G; matrix[45].b = V_ON_B; matrix[46].r = V_ON_R; matrix[46].g = V_ON_G; matrix[46].b = V_ON_B; matrix[47].r = V_ON_R; matrix[47].g = V_ON_G; matrix[47].b = V_ON_B; hours_to_show++; break; case 30: //halb x+1 matrix[44].r = V_ON_R; matrix[44].g = V_ON_G; matrix[44].b = V_ON_B; matrix[45].r = V_ON_R; matrix[45].g = V_ON_G; matrix[45].b = V_ON_B; matrix[46].r = V_ON_R; matrix[46].g = V_ON_G; matrix[46].b = V_ON_B; matrix[47].r = V_ON_R; matrix[47].g = V_ON_G; matrix[47].b = V_ON_B; hours_to_show++; break; case 35: //fŸnf nach halb x+1 matrix[7].r = V_ON_R; matrix[7].g = V_ON_G; matrix[7].b = V_ON_B; matrix[8].r = V_ON_R; matrix[8].g = V_ON_G; matrix[8].b = V_ON_B; matrix[9].r = V_ON_R; matrix[9].g = V_ON_G; matrix[9].b = V_ON_B; matrix[10].r = V_ON_R; matrix[10].g = V_ON_G; matrix[10].b = V_ON_B; matrix[40].r = V_ON_R; matrix[40].g = V_ON_G; matrix[40].b = V_ON_B; matrix[41].r = V_ON_R; matrix[41].g = V_ON_G; matrix[41].b = V_ON_B; matrix[42].r = V_ON_R; matrix[42].g = V_ON_G; matrix[42].b = V_ON_B; matrix[43].r = V_ON_R; matrix[43].g = V_ON_G; matrix[43].b = V_ON_B; matrix[44].r = V_ON_R; matrix[44].g = V_ON_G; matrix[44].b = V_ON_B; matrix[45].r = V_ON_R; matrix[45].g = V_ON_G; matrix[45].b = V_ON_B; matrix[46].r = V_ON_R; matrix[46].g = V_ON_G; matrix[46].b = V_ON_B; matrix[47].r = V_ON_R; matrix[47].g = V_ON_G; matrix[47].b = V_ON_B; hours_to_show++; break; case 40: //zehn nach halb x+1 matrix[11].r = V_ON_R; matrix[11].g = V_ON_G; matrix[11].b = V_ON_B; matrix[12].r = V_ON_R; matrix[12].g = V_ON_G; matrix[12].b = V_ON_B; matrix[13].r = V_ON_R; matrix[13].g = V_ON_G; matrix[13].b = V_ON_B; matrix[14].r = V_ON_R; matrix[14].g = V_ON_G; matrix[14].b = V_ON_B; matrix[40].r = V_ON_R; matrix[40].g = V_ON_G; matrix[40].b = V_ON_B; matrix[41].r = V_ON_R; matrix[41].g = V_ON_G; matrix[41].b = V_ON_B; matrix[42].r = V_ON_R; matrix[42].g = V_ON_G; matrix[42].b = V_ON_B; matrix[43].r = V_ON_R; matrix[43].g = V_ON_G; matrix[43].b = V_ON_B; matrix[44].r = V_ON_R; matrix[44].g = V_ON_G; matrix[44].b = V_ON_B; matrix[45].r = V_ON_R; matrix[45].g = V_ON_G; matrix[45].b = V_ON_B; matrix[46].r = V_ON_R; matrix[46].g = V_ON_G; matrix[46].b = V_ON_B; matrix[47].r = V_ON_R; matrix[47].g = V_ON_G; matrix[47].b = V_ON_B; hours_to_show++; break; case 45: //dreiviertel x+1 matrix[22].r = V_ON_R; matrix[22].g = V_ON_G; matrix[22].b = V_ON_B; matrix[23].r = V_ON_R; matrix[23].g = V_ON_G; matrix[23].b = V_ON_B; matrix[24].r = V_ON_R; matrix[24].g = V_ON_G; matrix[24].b = V_ON_B; matrix[25].r = V_ON_R; matrix[25].g = V_ON_G; matrix[25].b = V_ON_B; matrix[26].r = V_ON_R; matrix[26].g = V_ON_G; matrix[26].b = V_ON_B; matrix[27].r = V_ON_R; matrix[27].g = V_ON_G; matrix[27].b = V_ON_B; matrix[28].r = V_ON_R; matrix[28].g = V_ON_G; matrix[28].b = V_ON_B; matrix[29].r = V_ON_R; matrix[29].g = V_ON_G; matrix[29].b = V_ON_B; matrix[30].r = V_ON_R; matrix[30].g = V_ON_G; matrix[30].b = V_ON_B; matrix[31].r = V_ON_R; matrix[31].g = V_ON_G; matrix[31].b = V_ON_B; hours_to_show++; break; case 50: //zehn vor x+1 matrix[11].r = V_ON_R; matrix[11].g = V_ON_G; matrix[11].b = V_ON_B; matrix[12].r = V_ON_R; matrix[12].g = V_ON_G; matrix[12].b = V_ON_B; matrix[13].r = V_ON_R; matrix[13].g = V_ON_G; matrix[13].b = V_ON_B; matrix[14].r = V_ON_R; matrix[14].g = V_ON_G; matrix[14].b = V_ON_B; matrix[33].r = V_ON_R; matrix[33].g = V_ON_G; matrix[33].b = V_ON_B; matrix[34].r = V_ON_R; matrix[34].g = V_ON_G; matrix[34].b = V_ON_B; matrix[35].r = V_ON_R; matrix[35].g = V_ON_G; matrix[35].b = V_ON_B; hours_to_show++; break; case 55: //fŸnf vor x+1 matrix[7].r = V_ON_R; matrix[7].g = V_ON_G; matrix[7].b = V_ON_B; matrix[8].r = V_ON_R; matrix[8].g = V_ON_G; matrix[8].b = V_ON_B; matrix[9].r = V_ON_R; matrix[9].g = V_ON_G; matrix[9].b = V_ON_B; matrix[10].r = V_ON_R; matrix[10].g = V_ON_G; matrix[10].b = V_ON_B; matrix[33].r = V_ON_R; matrix[33].g = V_ON_G; matrix[33].b = V_ON_B; matrix[34].r = V_ON_R; matrix[34].g = V_ON_G; matrix[34].b = V_ON_B; matrix[35].r = V_ON_R; matrix[35].g = V_ON_G; matrix[35].b = V_ON_B; hours_to_show++; break; } if (hours_to_show >= 13) { hours_to_show = 1; } switch (hours_to_show) { case 1: //EINS matrix[55].r = V_ON_R; matrix[55].g = V_ON_G; matrix[55].b = V_ON_B; matrix[56].r = V_ON_R; matrix[56].g = V_ON_G; matrix[56].b = V_ON_B; matrix[57].r = V_ON_R; matrix[57].g = V_ON_G; matrix[57].b = V_ON_B; matrix[58].r = V_ON_R; matrix[58].g = V_ON_G; matrix[58].b = V_ON_B; break; case 2: //ZWEI matrix[62].r = V_ON_R; matrix[62].g = V_ON_G; matrix[62].b = V_ON_B; matrix[63].r = V_ON_R; matrix[63].g = V_ON_G; matrix[63].b = V_ON_B; matrix[64].r = V_ON_R; matrix[64].g = V_ON_G; matrix[64].b = V_ON_B; matrix[65].r = V_ON_R; matrix[65].g = V_ON_G; matrix[65].b = V_ON_B; break; case 3: //DREI matrix[66].r = V_ON_R; matrix[66].g = V_ON_G; matrix[66].b = V_ON_B; matrix[67].r = V_ON_R; matrix[67].g = V_ON_G; matrix[67].b = V_ON_B; matrix[68].r = V_ON_R; matrix[68].g = V_ON_G; matrix[68].b = V_ON_B; matrix[69].r = V_ON_R; matrix[69].g = V_ON_G; matrix[69].b = V_ON_B; break; case 4: //VIER matrix[73].r = V_ON_R; matrix[73].g = V_ON_G; matrix[73].b = V_ON_B; matrix[74].r = V_ON_R; matrix[74].g = V_ON_G; matrix[74].b = V_ON_B; matrix[75].r = V_ON_R; matrix[75].g = V_ON_G; matrix[75].b = V_ON_B; matrix[76].r = V_ON_R; matrix[76].g = V_ON_G; matrix[76].b = V_ON_B; break; case 5: //F†NF matrix[51].r = V_ON_R; matrix[51].g = V_ON_G; matrix[51].b = V_ON_B; matrix[52].r = V_ON_R; matrix[52].g = V_ON_G; matrix[52].b = V_ON_B; matrix[53].r = V_ON_R; matrix[53].g = V_ON_G; matrix[53].b = V_ON_B; matrix[54].r = V_ON_R; matrix[54].g = V_ON_G; matrix[54].b = V_ON_B; break; case 6: //SECHS matrix[77].r = V_ON_R; matrix[77].g = V_ON_G; matrix[77].b = V_ON_B; matrix[78].r = V_ON_R; matrix[78].g = V_ON_G; matrix[78].b = V_ON_B; matrix[79].r = V_ON_R; matrix[79].g = V_ON_G; matrix[79].b = V_ON_B; matrix[80].r = V_ON_R; matrix[80].g = V_ON_G; matrix[80].b = V_ON_B; matrix[81].r = V_ON_R; matrix[81].g = V_ON_G; matrix[81].b = V_ON_B; break; case 7: //SIEBEN matrix[88].r = V_ON_R; matrix[88].g = V_ON_G; matrix[88].b = V_ON_B; matrix[89].r = V_ON_R; matrix[89].g = V_ON_G; matrix[89].b = V_ON_B; matrix[90].r = V_ON_R; matrix[90].g = V_ON_G; matrix[90].b = V_ON_B; matrix[91].r = V_ON_R; matrix[91].g = V_ON_G; matrix[91].b = V_ON_B; matrix[92].r = V_ON_R; matrix[92].g = V_ON_G; matrix[92].b = V_ON_B; matrix[93].r = V_ON_R; matrix[93].g = V_ON_G; matrix[93].b = V_ON_B; break; case 8: //ACHT matrix[84].r = V_ON_R; matrix[84].g = V_ON_G; matrix[84].b = V_ON_B; matrix[85].r = V_ON_R; matrix[85].g = V_ON_G; matrix[85].b = V_ON_B; matrix[86].r = V_ON_R; matrix[86].g = V_ON_G; matrix[86].b = V_ON_B; matrix[87].r = V_ON_R; matrix[87].g = V_ON_G; matrix[87].b = V_ON_B; break; case 9: //NEUN matrix[102].r = V_ON_R; matrix[102].g = V_ON_G; matrix[102].b = V_ON_B; matrix[103].r = V_ON_R; matrix[103].g = V_ON_G; matrix[103].b = V_ON_B; matrix[104].r = V_ON_R; matrix[104].g = V_ON_G; matrix[104].b = V_ON_B; matrix[105].r = V_ON_R; matrix[105].g = V_ON_G; matrix[105].b = V_ON_B; break; case 10: //ZEHN matrix[99].r = V_ON_R; matrix[99].g = V_ON_G; matrix[99].b = V_ON_B; matrix[100].r = V_ON_R; matrix[100].g = V_ON_G; matrix[100].b = V_ON_B; matrix[101].r = V_ON_R; matrix[101].g = V_ON_G; matrix[101].b = V_ON_B; matrix[102].r = V_ON_R; matrix[102].g = V_ON_G; matrix[102].b = V_ON_B; break; case 11: //ELF matrix[49].r = V_ON_R; matrix[49].g = V_ON_G; matrix[49].b = V_ON_B; matrix[50].r = V_ON_R; matrix[50].g = V_ON_G; matrix[50].b = V_ON_B; matrix[51].r = V_ON_R; matrix[51].g = V_ON_G; matrix[51].b = V_ON_B; break; case 12: //ZW…LF matrix[94].r = V_ON_R; matrix[94].g = V_ON_G; matrix[94].b = V_ON_B; matrix[95].r = V_ON_R; matrix[95].g = V_ON_G; matrix[95].b = V_ON_B; matrix[96].r = V_ON_R; matrix[96].g = V_ON_G; matrix[96].b = V_ON_B; matrix[97].r = V_ON_R; matrix[97].g = V_ON_G; matrix[97].b = V_ON_B; matrix[98].r = V_ON_R; matrix[98].g = V_ON_G; matrix[98].b = V_ON_B; break; } //SonderfŠlle: if (hours_to_show == 1 && minutes_to_show < 5) //S von einS ausschalten bei "ein Uhr" { matrix[58].r = 0; matrix[58].g = 0; matrix[58].b = 0; } } else if (frontplatte == 1) { //Zeitanzeige fŸr BinŠre Frontplatte } else if (frontplatte == 2) { //Zeitanzeige fŸr Englische Frontplatte } //Ende der Frontplattenansteuerung if (matrix_on) { PORTC &= ~(1 << 1); //Mosfet anschalten ws2812_setleds(matrix, 111); } else { PORTC |= (1 << 1); //Mosfet ausschalten } }
int main() { DDRB |= _BV(5); PORTB &= ~_BV(5); ///////////////////////////// // Set up the analogue input setupAdcOnPin(0); adcStartConversion(); // Start ADC measurement pulseSetFrameBuffer(frameBuffer, NUM_LEDS); const uint8_t pulseCount = 10; uint8_t pulseIdx = 0; struct cPulse pulses[pulseCount]; memset(pulses, 0, sizeof(struct cPulse) * pulseCount); for (int i = 0; i < pulseCount; i += 2) { pulses[i].direction = 1; } uint8_t sampleHistory[HISTORY_COUNT]; memset(sampleHistory, 0, HISTORY_COUNT); int8_t startingPosition = 0; while(1) { ++toggle; toggle = toggle % 50; setIndicator(toggle == 0); // Hist = = = = = // Wind - - // Copy - - for (int i = 0; i < (HISTORY_COUNT - WINDOW_SIZE); ++i) { sampleHistory[i] = sampleHistory[i + WINDOW_SIZE]; } for (int i = 0; i < WINDOW_SIZE; ++i) { adcStartConversion(); _delay_us(500); adcWaitReady(); sampleHistory[WINDOW_START + i] = ADCH; } uint8_t historicalPeak = findPeak(sampleHistory, 0, WINDOW_START); uint8_t currentPeak = findPeak(sampleHistory, WINDOW_START, WINDOW_SIZE); if (isPulseDetected(historicalPeak, currentPeak)) { // Generate a new pulse if (++pulseIdx >= pulseCount) pulseIdx = 0; pulses[pulseIdx].colour.h = rand() % MAX_HUE; pulses[pulseIdx].colour.s = (MAX_SAT / 2) + (rand() % (MAX_SAT / 2)); pulses[pulseIdx].colour.v = MAX_VAL; pulses[pulseIdx].position = startingPosition; startingPosition -= 3; if (startingPosition < 0) startingPosition += NUM_LEDS; } pulseClearFrameBuffer(); for (int i = 0; i < pulseCount; ++i) { pulseUpdate(pulses + i); pulseRender(pulses + i); } ws2812_setleds(frameBuffer, 40); // Blocks for ~1.2ms _delay_ms(2); // The sensor line will be noisy for a little while } }
int main(void) { #ifdef __AVR_ATtiny10__ CCP=0xD8; // configuration change protection, write signature CLKPSR=0; // set cpu clock prescaler =1 (8Mhz) (attiny 4/5/9/10) #else CLKPR=_BV(CLKPCE); CLKPR=0; // set clock prescaler to 1 (attiny 25/45/85/24/44/84/13/13A) #endif uint64_t i, j, rr, rg, rb, rR, rG, rB, k, d, l, rz; for (i=0; i<255; i++) { led[0].r = led[0].g = led[0].b = i; led[1].r = led[1].g = led[1].b = 255-i; ws2812_setleds(led,3); _delay_ms(3); } for (i=255; i>0; i--) { led[0].r = led[0].g = led[0].b = i; led[1].r = led[1].g = led[1].b = 255-i; ws2812_setleds(led,3); _delay_ms(3); } _delay_ms(100); rR = rG = rB = 0; // k = 100; d = 255; l = 64; for (i=0; i<30; i++) { rz = rand() % 3; rr = rand() % l * ((rz+2)%3); rg = rand() % l * ((rz+1)%3); rb = rand() % l * ((rz)%3); for (j=0; j<d;j++){ led[0].r = ((rr * j / d) + (rR * (d-j) / d)); led[0].g = ((rg * j / d) + (rG * (d-j) / d)); led[0].b = ((rb * j / d) + (rB * (d-j) / d)); led[1].r = 127-led[0].r; led[1].g = 127-led[0].g; led[1].b = 127-led[0].b; ws2812_setleds(led,3); _delay_ms(5); } rR = rr; rG = rg; rB = rb; _delay_ms(100); } _delay_ms(100000); for (i=0; i<255; i++) { led[0].r = i; led[1].r = i; ws2812_setleds(led,3); _delay_ms(3); } for (i=255; i>0; i--) { led[0].r = i; led[1].r = i; ws2812_setleds(led,3); _delay_ms(3); } for (i=0; i<255; i++) { led[0].r = led[0].b = i; led[1].r = led[1].b = i; ws2812_setleds(led,3); _delay_ms(3); } for (i=255; i>0; i--) { led[0].r = led[0].b = i; led[1].r = led[1].b = i; ws2812_setleds(led,3); _delay_ms(3); } for(i=0; i<100; i++) { led[0].r = rand() % 256; led[0].g = rand() % 256; led[0].b = rand() % 256; led[1].r = rand() % 256; led[1].g = rand() % 256; led[1].b = rand() % 256; ws2812_setleds(led,3); _delay_ms(30); } // while(1){ for(i=0; i<100; i++) { led[0].r = 255 * rand() % 2; led[0].g = 255 * rand() % 2; led[0].b = 255 * rand() % 2; led[1].r = 255 * rand() % 2; led[1].g = 255 * rand() % 2; led[1].b = 255 * rand() % 2; ws2812_setleds(led,3); _delay_ms(30); } for(i=0; i<10000; i++) { j = 1ULL << (i % 48); led[0].r = ( j ) ; led[0].g = ( j >> 4 ) ; led[0].b = ( j >> 8 ) ; led[1].r = ( j / 8 >> 0 ) ; led[1].g = ( j / 8 >> 8 ) ; led[1].b = ( j / 8 >> 16) ; ws2812_setleds(led,3); _delay_ms(10); } // while(1) for(i=0; i<100; i++) { led[0].r=255;led[0].g=00;led[0].b=0; // Write red to array ws2812_setleds(led,2); _delay_ms(500); // wait for 500ms. led[0].r=0;led[0].g=255;led[0].b=0; // green ws2812_setleds(led,1); _delay_ms(500); led[0].r=0;led[0].g=00;led[0].b=255; // blue ws2812_setleds(led,1); _delay_ms(500); } }