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
|
void ledInit(void) //设定led(初始化) { softPwmCreate(LedPinRed, 0, 100); //pwm的取值范围,最高255 softPwmCreate(LedPinGreen,0, 100); softPwmCreate(LedPinBlue,0, 255); } void ledColorSet(uchar r_val, uchar g_val,uchar b_val) { softPwmWrite(LedPinRed, r_val); //写入pwm的值,不同的值实现不同的亮度 softPwmWrite(LedPinGreen, g_val); softPwmWrite(LedPinBlue, b_val); } int main(void) { int i; if(wiringPiSetup() == -1){ //初始化wiringpi库 printf("setup wiringPi failed !"); return 1; } ledInit(); //led初始化 while(1){ //控制灯及亮度 //ledColorSet(0xff,0x00,0x00); //delay(500); //ledColorSet(0x00,0xff,0x00); //delay(500); //ledColorSet(0x00,0x00,0x0); //delay(500); //ledColorSet(0x00,0x00,0x4); //delay(500); //ledColorSet(0x00,0x00,0x8); //delay(500); //ledColorSet(0x00,0x00,0x9); //delay(500); //ledColorSet(0x00,0x00,0x10); //delay(500); //ledColorSet(0x00,0x00,0x11); //delay(500); //ledColorSet(0x00,0x00,0x22); //delay(500); //ledColorSet(0x00,0x00,0x33); //delay(500); //ledColorSet(0x00,0x00,0x44); //delay(500); //ledColorSet(0x00,0x00,0x55); //delay(500); //ledColorSet(0x00,0x00,0x64); //delay(500); //ledColorSet(0x00,0x00,0x0); //delay(500); ledColorSet(0,0,200); delay(50000); //ledColorSet(0xff,0x45); //delay(500); //ledColorSet(0xff,0xff); //delay(500); //ledColorSet(0x7c,0xfc); //delay(500); } return 0; }
|