project will allow the user to cycle or select a
RGB color to be displayed on the RGB LED on the EA base board.
#define REDCHAN 0
#define GREENCHAN 1
#define BLUECHAN 2
unsigned char color[N][3]={ {0xff, 0, 0},
{0, 0xff, 0},
{0, 0, 0xff},
{0xff, 0xff, 0}.....};
pwm_red=color[desired_col][REDCHAN];
pwm_green=color[desired_col][GREENCHAN];
pwm_blue=color[desired_col][BLUECHAN];
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 #define F_CPU 16000000UL #include <avr/io.h> #include <util/delay.h> #define buttonport PORTC #define buttonportpin PINC #define buttonddr DDRC #define ledport1 PORTC #define ledport2 PORTD #define ledport3 PORTB #define ledddr1 DDRC #define ledddr2 DDRD #define ledddr3 DDRB #define buttonpin 0 #define ledpin1 1 //d4 #define ledpin2 0 //d2 #define ledpin3 6 //d1 void main() { int i=0,j; buttonddr = buttonddr & ~(1<<buttonpin); ledddr1 = ledddr1 | (1<<ledpin1); ledddr2 = ledddr2 | (1<<ledpin2); ledddr3 = ledddr3 | (1<<ledpin3); while(1) { ledport1 = ledport1 | (0<<ledpin1); ledport2 = ledport2 | (0<<ledpin2); ledport3 = ledport3 | (0<<ledpin3); if((buttonportpin & (1<<buttonpin))==0) { _delay_ms(30); if((buttonportpin & (1<<buttonpin))==0) { while (!(buttonportpin & (1<<buttonpin))) { i=1; } } if(!((buttonportpin & (1<<buttonpin))==0)) { _delay_ms(1000); if((buttonportpin & (1<<buttonpin))==0) { _delay_ms(30); if((buttonportpin & (1<<buttonpin))==0) { while (!(buttonportpin & (1<<buttonpin))) { i=i+1; while((buttonportpin & (1<<buttonpin))==0); } } } j=i%4; switch(j) { case 1: { ledport1 = ledport1 | (1<<1); _delay_ms(3000); ledport1 = ledport1 & (0<<1); break; } case 2: { ledport2 = ledport2 | (1<<0); _delay_ms(3000); ledport2 = ledport2 & (0<<0); break; } case 3: { ledport3 = ledport3 | (1<<6); _delay_ms(3000); ledport3 = ledport3 & (0<<6); break; } } } } } return 0; }
If you can edit the post to use the '#' tag around the code (so that indents are visible), it will be easier to
follow the code, to see if it can be made to work.
// Port A
#define CHARGE_EN 0x04
#define VIDEO_EN 0x08
#define DRV_EN 0x10
#define EXTLED 0x40
#define BOARDLED 0x80
// outputs
#define BOARDLED_ON PORTA |= BOARDLED
#define BOARDLED_OFF PORTA &= ~BOARDLED
#define DRV_ON PORTA |= DRV_EN
#define DRV_OFF PORTA &= ~DRV_EN
#define CHARGE_ON PORTA |= CHARGE_EN
#define CHARGE_OFF PORTA &= ~CHARGE_EN
while(1)
{
BOARDLED_ON;
delay_ms(100);
BOARDLED_OFF;
delay_ms(100);
}
while(1)
{
ledport1 = ledport1 | (0<<ledpin1);
ledport2 = ledport2 | (0<<ledpin2);
ledport3 = ledport3 | (0<<ledpin3);
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?