Hey guys, I have a quick question. I have 3 pins going to an LED (I've successfully used PWM to fade in and out of green thanks to earlier help ^^ ). Now, I would like to change the color. I'm not going to impose random color shifts just yet, so I would like to have discrete color fade-ins (ex. fade in and out of green, then change color to blue and fade in and out, then red, light blue, etc.)
Note: Compiler is C18 and I am using a PIC18F4550
I understand that to define pin variables you use for example:
Or you could define a variable for the entire port, for example:
So, my question is how do I define three pins to a variable? So for example (psuedo code):
Would I need to create struct that holds 3 bits like so?
And then shift and mask each bit in "LEDcolor.colorCode" and then set it equal to LATA variables (LED1,2,3)? In a nut shell, is there an easy way to create a three bit variable for LAT pins so I can easily update those pins?
Note: Compiler is C18 and I am using a PIC18F4550
I understand that to define pin variables you use for example:
Code:
#define LED1 LATAbits.LATA0
#define LED2 LATAbits.LATA1
#define LED3 LATAbits.LATA2
Or you could define a variable for the entire port, for example:
Code:
#define allOfPortAbits LATA
So, my question is how do I define three pins to a variable? So for example (psuedo code):
Code:
#define threePins LATAbits.LATA<0-2>
Would I need to create struct that holds 3 bits like so?
Code:
typedef struct{
unsigned colorCode : 3;
}myLEDcolor;
myLEDcolor LEDcolor;
And then shift and mask each bit in "LEDcolor.colorCode" and then set it equal to LATA variables (LED1,2,3)? In a nut shell, is there an easy way to create a three bit variable for LAT pins so I can easily update those pins?
Last edited: