树梅派学习 4. 双色LED实验

实践是知识的母亲,知识是生活的明灯。这篇文章主要讲述树梅派学习 4. 双色LED实验相关的知识,希望能为你提供帮助。
实体接线:

到树梅派新建文件 :
/home/pi/study/01.DualLED/C
新建:
dule_color_led.c

#include < wiringPi.h>
#include < softPwm.h>
#include < stdio.h>

#define uchar unsigned char

#define LedPinRed0
#define LedPinGreen1

void ledInit(void)

softPwmCreate(LedPinRed,0, 100);
softPwmCreate(LedPinGreen,0, 100);


void ledColorSet(uchar r_val, uchar g_val)

softPwmWrite(LedPinRed,r_val);
softPwmWrite(LedPinGreen, g_val);


int main(void)

int i;

if(wiringPiSetup() == -1) //when initialize wiring failed,print messageto screen
printf("setup wiringPi failed !");
return 1;

//printf("linker LedPin : GPIO %d(wiringPi pin)\\n",LedPin); //when initialize wiring successfully,print message to screen

ledInit();

while(1)
ledColorSet(0xff,0x00); //red
delay(500);
ledColorSet(0x00,0xff); //green
delay(500);
ledColorSet(0xff,0x45);
delay(500);
ledColorSet(0xff,0xff);
delay(500);
ledColorSet(0x7c,0xfc);
delay(500);


return 0;

编译运行:
gcc dule_color_led.c -o led -lwiringPi -lpthread
./led


运行结果可以看到双色灯红、黄交替闪烁。
【树梅派学习 4. 双色LED实验】


    推荐阅读