Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <avr/delay.h>
- int maxValue(int x) {
- if (x > 255) {
- return 255;
- }
- return x;
- }
- int minValue(int x) {
- if (x < 0) {
- return 0;
- }
- return x;
- }
- int main(void) {
- TCCR0|=(1<<WGM00)|(1<<WGM01)|(1<<COM01)|(0<<CS02)|(0<<CS01)|(1<<CS00);
- TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11);
- TCCR1B|=(1<<WGM13)|(1<<WGM12)|(0<<CS12)|(0<<CS11)|(1<<CS10);
- ICR1=255;
- DDRB |= (1 << PB3);
- DDRD |= (1 << PD5) | (1 << PD4);
- DDRA = 0x00; // in
- PORTA = 0xFF;
- int r = 255;
- int g = 255;
- int b = 255;
- OCR0 = r; // PB3, R
- OCR1A = g; // PD5, G
- OCR1B = b; // PD4, B
- int constN = 255 / 7;
- int lastButton = 0;
- while (1) {
- if (PINA == lastButton) {
- continue;
- }
- lastButton = PINA;
- switch (PINA) {
- // R
- case 0b11111110:
- r += constN;
- r = maxValue(r);
- OCR0 = r;
- break;
- case 0b11111101:
- r -= constN;
- r = minValue(r);
- OCR0 = r;
- break;
- // G
- case 0b11111011:
- g += constN;
- g = maxValue(g);
- OCR1A = g;
- break;
- case 0b11110111:
- g -= constN;
- g = minValue(g);
- OCR1A = g;
- break;
- // B
- case 0b11101111:
- b += constN;
- b = maxValue(b);
- OCR1B = b;
- break;
- case 0b11011111:
- b -= constN;
- b = minValue(b);
- OCR1B = b;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement