#include <wiringPi.h>
#include <stdio.h>
#include <string.h>
#define SWITCHER1 26
#define SWITCHER2 27
#define SWITCHER3 28
#define SWITCHER4 29
int main()
{
char cmd[128] = {’\0’};
if(wiringPiSetup() == -1){
printf(“硬件接口初始化失败\n”);
return -1;
}
pinMode(SWITCHER1,OUTPUT);
pinMode(SWITCHER2,OUTPUT);
pinMode(SWITCHER3,OUTPUT);
pinMode(SWITCHER4,OUTPUT);
digitalWrite(SWITCHER1,HIGH);
digitalWrite(SWITCHER2,HIGH);
digitalWrite(SWITCHER3,HIGH);
digitalWrite(SWITCHER4,HIGH);
while(1) {
printf("请输入1/2/3/4:off断开开关,on导通开关\n");
memset(cmd,'\0',sizeof(cmd));
// scanf("%s",cmd);
gets(cmd);
if(strcmp(cmd,"1 on") == 0) {
digitalWrite(SWITCHER1,LOW);
} else if(strcmp(cmd,"1 off") == 0) {
digitalWrite(SWITCHER1,HIGH);
}
if(strcmp(cmd,"2 on") == 0) {
digitalWrite(SWITCHER2,LOW);
} else if(strcmp(cmd,"2 off") == 0) {
digitalWrite(SWITCHER2,HIGH);
}
if(strcmp(cmd,"3 on") == 0) {
digitalWrite(SWITCHER3,LOW);
} else if(strcmp(cmd,"3 off") == 0) {
digitalWrite(SWITCHER3,HIGH);
}
if(strcmp(cmd,"4 on") == 0) {
digitalWrite(SWITCHER4,LOW);
} else if(strcmp(cmd,"4 off") == 0) {
digitalWrite(SWITCHER4,HIGH);
}
if(strcmp(cmd,"all on") == 0) {
digitalWrite(SWITCHER1,LOW);
digitalWrite(SWITCHER2,LOW);
digitalWrite(SWITCHER3,LOW);
digitalWrite(SWITCHER4,LOW);
} else if(strcmp(cmd,"all off") == 0) {
digitalWrite(SWITCHER1,HIGH);
digitalWrite(SWITCHER2,HIGH);
digitalWrite(SWITCHER3,HIGH);
digitalWrite(SWITCHER4,HIGH);
}
else {
printf("输入错误\n");
}
}
return 0;
}