Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 1000000UL
- #include "avr/io.h"
- #include "util/delay.h"
- #include "avr/interrupt.h"
- uint8_t brightness[3] = {5, 125, 250};
- int dir [3] = {1,1,0}; //1 for up, 0 for down
- uint8_t i;
- int main(void)
- {
- cli();
- DDRA |= 1<<DDA7;
- DDRA |= 1<<DDA6;
- DDRA |= 1<<DDA5; //pins 6,7,8 set to output
- //Set up PWM pin 6 (OC0B)
- TCCR0A |= 1<<COM0B1;
- TCCR0A |= 1<<WGM00;
- TCCR0A |= 1<<WGM01;
- TCCR0B |= 1<<CS00; //clk no prescaling
- OCR0B = brightness[0];
- //Set up PWM pin 7,8 (OC1A/OC1B)
- TCCR1A |= 1<<COM1A1;
- TCCR1A |= 1<<COM1B1;
- TCCR1A |= 1<<WGM10;
- TCCR1B |= 1<<WGM12;
- TCCR1B |= 1<<CS10;
- OCR1A = brightness[1];
- OCR1B = brightness[2];
- sei();
- while(1)
- {
- for(i = 0; i < 3; i++){
- if(brightness[i] >= 255){
- dir[i] = 0;
- } else if (brightness[i] <= 5){
- dir[i] = 1;
- }
- if(dir[i]){
- brightness[i] = brightness[i] + 5;
- } else {
- brightness[i] = brightness[i] - 5;
- }
- }
- OCR0B = brightness[0];
- OCR1A = brightness[1];
- OCR1B = brightness[2];
- _delay_ms(30);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement