Write a MplabX IDE PIC10f200 code that work with three LEDs red, blue and green
ID: 1766271 • Letter: W
Question
Write a MplabX IDE PIC10f200 code that work with three LEDs red, blue and green as a mood light.( mood light has 7 colors. When all the leds terns on we will get white color, green and red tern on to get yellow, red to get red, red and blue tern on to get purple, just blue to get blue, blue and green to get light blue and just green led terns on to get green) then replay again. Write a MplabX IDE PIC10f200 code that work with three LEDs red, blue and green as a mood light.( mood light has 7 colors. When all the leds terns on we will get white color, green and red tern on to get yellow, red to get red, red and blue tern on to get purple, just blue to get blue, blue and green to get light blue and just green led terns on to get green) then replay again.Explanation / Answer
#define _XTAL_FREQ 8000000
void main(void) {
int i=0;
int v;
int r,g,b; // to store the PWM ratio of each color
unsigned char c=0x00; // to store the pin output value
TRISC=0b00000000;
PORTC=0b00000000;
ANSEL = 0x00;
ANSELH = 0x00;
r=5; // Red ligt will remains fixed to intensity 5/255
for (i=0;i<=255;i++) { // a loop to vary the leds intensity
g=i; // Green led will light from 0 to 255
b=255-i; // Blue led will light from 255 to 0
for (v=0;v<=255;v++) { // loop to simulate PWM over 256 values
if (v<r) { // if current v valuer is < to the red led intensity
c|=0b00000001; // we light the led
} else {
c&=0b11111110; // else we shut it.
}
if (v<g) { // same for green
c|=0b00000010;
} else {
c&=0b11111101;
}
if (v<b) { // same for blue
c|=0b00000100;
} else {
c&=0b11111011;
}
PORTC=c; // and we finaly push the led status to PORTC (R led on C0, G led on C1 and blue on C2)
__delay_us(1); // make a short break.
}
}
return;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.