aaaaaaaa吧 关注:938贴子:2,120
  • 1回复贴,共1
//
//红绿灯
//
#include <iostream>
#include <wiringPi.h>
using namespace std;
const int red = 1;//GPIO 1
const int yellow = 4;//GPIO 4
const int green = 5;//GPIO 5
int main(void){
if ( wiringPiSetup 0 ==-1 )//设定WiringPi
return 0;
pinMode( red, OUTPUT );//设定为输出
pinMode( yellow, OUTPUT );
pinMode( green, OUTPUT);
while( 1 ){
//绿灯(五秒)
digitalWrite( red,0 );
digitalWrite( yellow,0 );
digitalWrite( green, 1 );
delay( 5000 );
//黄橙(闪烁4次)
digitalWrite( red, 0 );
digitalWrite( green, 0 );
for ( int i=0;i<4 ;i++){
digitalWrite( yellow, 1 );
delay( 500 );
digitalWrite( yellow,0 );
delay( 500 );
}
//红橙(5秒)
digitalWrite( red, 1 );
digitalWrite( yellow,0 );
digitalWrite( green,0 );
delay( 5000 );
return 1;


1楼2020-12-13 17:35回复
    //
    //PWM控制LED
    //
    #include <iostream>
    #include <wiringPi.h>
    #include <softPwm.h>
    using namespace std;
    const int led = 1;// GPIO1
    int main (void) {
    if ( wiringPiSetup ()==-1)//设定WiringPi
    return 0;
    softPwmCreate( led, 0,100 );//设定软醋 PWM值介於0~100之間
    while ( 1 ){
    int val;
    for ( val = 0 ; val <= 100 ; val++){//从暗樊亮
    softPwmWrite( led, val );
    delay( 20 );
    }
    for ( val = 100 ; val >= 0 ; val--){//徙亮燮暗
    softPwmWrite( led, val );
    delay( 20 );
    }
    }
    return 1;
    }


    2楼2020-12-13 17:36
    回复