Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <stdint.h>
- #include <avr/interrupt.h>
- #include <math.h>
- #include <util/delay.h>
- struct
- {
- const uint8_t fioletowy[3] = {255,0,255};
- const uint8_t blekitny[3] = {0,255,255};
- const uint8_t czerwony[3] = {255,0,0};
- const uint8_t zielony[3] = {0,255,0};
- const uint8_t niebieski[3] = {0,0,255};
- const uint8_t pomaranczowy[3] = {255,128,0};
- const uint8_t zolty[3] = {255,255,0};
- const uint8_t bialy[3] = {255,255,255};
- const uint8_t rozowy[3] = {255,100,255};
- const uint8_t cyjanowy[3] = {0,255,225};
- } kolory;
- void setPwm(uint8_t channel, uint8_t pwm)
- {
- switch(channel)
- {
- case 1:
- OCR1A = pwm;
- break;
- case 2:
- OCR1B = pwm;
- break;
- case 3:
- OCR2A = pwm;
- break;
- }
- }
- int main()
- {
- PORTD &= ( (1<<PD1) & (1<<PD2) );
- DDRD |= ( (1<<PD1) | (1<<PD2) );
- TCCR1A |= ( (1<<COM1A1) | (1<<COM1B1 | (1<<COM1B0) | (1<<COM1A0)) );
- TCCR1A |= (1<<WGM10);
- TCCR1B |= ( (1<<WGM12) | (1<<CS11) );
- TCCR2A |= ( (1<<COM2A1) | (1<<COM2B1) | (1<<COM2B0) | (1<<COM2A0) );
- TCCR2A |= (1<<WGM20);
- TCCR2B |= ( (1<<WGM21) | (1<<CS21) );
- DDRB |= ( 1<<PB1 | 1<<PB2 | 1<<PB3 );
- while(1)
- {
- setPwm(1, 0);
- setPwm(2, 0);
- setPwm(3, 0);
- _delay_ms(500);
- setPwm(1, 128);
- setPwm(2, 128);
- setPwm(3, 128);
- _delay_ms(500);
- setPwm(1, 255);
- setPwm(2, 255);
- setPwm(3, 255);
- _delay_ms(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment