//
//红绿灯
//
#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;
//红绿灯
//
#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;