49 lines
884 B
C
49 lines
884 B
C
|
/*
|
||
|
* led.c
|
||
|
*
|
||
|
* Created: 06.10.2013 16:32:15
|
||
|
* Author: netz
|
||
|
*/
|
||
|
|
||
|
#include <avr/io.h>
|
||
|
#include "led.h"
|
||
|
|
||
|
void led(int mask) {
|
||
|
int rgb = 0;
|
||
|
rgb |= (mask & (1<<0)) ? (1<<0) : (0<<0);
|
||
|
rgb |= (mask & (1<<1)) ? (1<<1) : (0<<1);
|
||
|
rgb |= (mask & (1<<2)) ? (1<<2) : (0<<2);
|
||
|
|
||
|
PORTB &= ~((1<<PINB5) | (1<<PINB6) | (1<<PINB7));
|
||
|
PORTB |= (rgb<<PINB5);
|
||
|
}
|
||
|
|
||
|
void init_led()
|
||
|
{
|
||
|
DDRB |= (1<<PINB7) | (1<<PINB6) | (1<<PINB5);
|
||
|
}
|
||
|
|
||
|
void fade(int from, int to, int dur) {
|
||
|
for (int i=0;i<0xFF;i++) {
|
||
|
for(int k=0;k<dur;k++) {
|
||
|
for (int j=i;j<0xFF;j++) {
|
||
|
led(from);
|
||
|
}
|
||
|
for (int j=0;j<i;j++) {
|
||
|
led(to);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void led_rainbow(uint8_t t) {
|
||
|
fade(WHITE, RED, 10);
|
||
|
while(1) {
|
||
|
fade(RED, YELLOW, t);
|
||
|
fade(YELLOW, GREEN, t);
|
||
|
fade(GREEN, CYAN, t);
|
||
|
fade(CYAN, BLUE, t);
|
||
|
fade(BLUE, MAGENTA, t);
|
||
|
fade(MAGENTA, RED, t);
|
||
|
}
|
||
|
}
|