-
硬件连线
vcc 接3.3V ——板子内侧的一排引脚
GND 接地
IN接 pin4
接线图: -
树莓派引脚
gpio readall //查看gpio引脚
-
demo
vi demo1.c
#include<stdio.h>
#include<wiringPi.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 demo1.c -lwiringPi //编译