0% found this document useful (0 votes)
5 views2 pages

Bài 1

The document contains a C program that uses the WiringPi library to control the brightness of RGB LEDs connected to specific GPIO pins. It defines functions to gradually increase and decrease the intensity of red, green, and blue LEDs using PWM signals. The main function sets up the GPIO pins and continuously cycles through the LED colors in an infinite loop.

Uploaded by

tyuiop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Bài 1

The document contains a C program that uses the WiringPi library to control the brightness of RGB LEDs connected to specific GPIO pins. It defines functions to gradually increase and decrease the intensity of red, green, and blue LEDs using PWM signals. The main function sets up the GPIO pins and continuously cycles through the LED colors in an infinite loop.

Uploaded by

tyuiop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
#include <wiringPi.h>
#include <unistd.h>

#define pw0_RED 12
#define pw1_GREEN 32
#define pw1_BLUE 33

void enalble_red(uint8_t pin)


{
for(uint8_t i = 0; i <=10; i++)
{
uint8_t intensity_led = 10*i;
pwmWrite(pin, intensity_led);
Delay(200);
}
for(uint8_t j = 0; j <=10; j++)
{
uint8_t intensity_led = 100 - 10*i;
pwmWrite(pin, intensity_led);
Delay(200);
}
}
void enalble_green(uint8_t pin)
{
for(uint8_t i = 0; i <=10; i++)
{
uint8_t intensity_led = 10*i;
pwmWrite(pin, intensity_led);
Delay(200);
}
for(uint8_t j = 1; j <=10; j++)
{
uint8_t intensity_led = 100 - 10*i;
pwmWrite(pin, intensity_led);
Delay(200);
}
}
void enalble_blue(uint8_t pin)
{
for(uint8_t i = 0; i <=10; i++)
{
uint8_t intensity_led = 10*i;
pwmWrite(pin, intensity_led);
Delay(200);
}
for(uint8_t j = 0; j <=10; j++)
{
uint8_t intensity_led = 100 - 10*i;
pwmWrite(pin, intensity_led);
Delay(200);
}
}
int main()
{
//Set up thư viện wiringPi
wiringPiSetupPhys();
//Khai báo chân IO
pinMode(pw0_RED, PWM_OUTPUT);
pinMode(pw0_GREEN, PWM_OUTPUT);
pinMode(pw0_BLUE, PWM_OUTPUT);
//Set chế độ cho module pwm0
pwmSetMode(PWM_MODE_MS);
pwmSetClock(15);
pwmSetRange(100);
while(1)
{
enalble_red(pw0_RED);
enalble_green(pw1_GREEN);
enalble_blue(pw1_BLUE);
}
return 0;
}

You might also like