#define F_CPU 9600000
#include <ctype.h>
#include <avr/io.h>
//#include <avr/iom8.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/wdt.h>
#include <avr/delay.h>
#include <stdlib.h>
#include "usiTwiSlave.h"
#define outp(a, b) b = a
#define i2cAddress 0x18
#define DDRB_MASK (1<< PB1)|(1<< PB3)|(1<< PB4)
#define MAX 256
#define TIME 1
int red = 0;
int green = 0;
int blue = 0;
int h = 0;
int brightness = 100;
void hue2rgb(int hue){
int hd = hue / 42; // 42 == 252/6, 252 == H_MAX
int hi = hd % 6; // gives 0-5
int f = hue % 42;
int fs = f * 6;
switch( hi ) {
case 0:
red = 252; green = fs; blue = 0;
break;
case 1:
red = 252-fs; green = 252; blue = 0;
break;
case 2:
red = 0; green = 252; blue = fs;
break;
case 3:
red = 0; green = 252-fs; blue = 252;
break;
case 4:
red = fs; green = 0; blue = 252;
break;
case 5:
red = 252; green = 0; blue = 252-fs;
break;
}
}
void delayms(uint16_t millis) {
uint16_t loop;
while ( millis ) {
_delay_ms(1);
millis--;
}
}
void setup(){
DDRB = DDRB_MASK;
TCCR0A=_BV(WGM00)|_BV(COM0A1)|_BV(WGM01)|_BV(COM0B1);
TCCR0B=_BV(CS00);
TCCR1=_BV(PWM1A)|_BV(COM1A1)|_BV(CS12);
GTCCR=_BV(PWM1B)|_BV(COM1B1); //PWM
}
/*
void colorPWM(int colorVal, int brightness, )
*/
int main(void) {
setup();
int i = 0;
uint8_t rxData;
while(1) {
for(int j = 0; j<MAX; j++){
hue2rgb(j);
OCR0B = green * (brightness/100); //functional one as of 8:14pm
OCR1B = red * (brightness/100);
PORTB &= ~(1<<PB3); /* LED on */
delayms(10);
}
/*
for(int k = 0; k<255; k++){
OCR0B = k;
OCR1B = k;
delayms(1);
}
for(int k = 255; k > 0; k--){
OCR0B = k;
OCR1B = k;
delayms(1);
}
*/
}
return 0;
}
/*
for(i=0;i<MAX;i++){
OCR1A=i; //works for blue, PB3
OCR1B=i; //green
OCR0A=i/4;
delayms(TIME);
}
for(i=MAX;i>0;i--){
OCR1A=i; //works for blue, PB3
OCR1B=i;
OCR0A=i/4;
delayms(TIME);
}
*/