demo2.c
#include<wiringPi.h>
#include<stdio.h>
#define SWITCHER 7
int main()
{
int cmd;
if(wiringPiSetup() == -1)
{
printf("硬件接口初始化失败\n");
return -1;
}
pinMode(SWITCHER,OUTPUT);//设置输出口
digitalWrite(SWITCHER,HIGH);//断开
while(1)
{
printf("请输入0/1:0-断开开关,1-导通开关\n");
scanf("%d",&cmd);
getchar();
if(cmd == 1)
{
digitalWrite(SWITCHER,LOW); }
else if(cmd == 0)
{
digitalWrite(SWITCHER,HIGH);
}
cmd = 10;
}
}
编译:gcc demo2.c -lwiringPi
运行结果: