arduinodigitalwrite可以设置为变量吗
发布网友
发布时间:2023-09-15 15:06
我来回答
共1个回答
热心网友
时间:2024-11-28 22:59
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void IO07(unsigned short int a){
int b[8];
b[0]=a%2;
b[1]=int(a/2)%2;
b[2]=int(a/4)%2;
b[3]=int(a/8)%2;
b[4]=int(a/16)%2;
b[5]=int(a/32)%2;
b[6]=int(a/62)%2;
b[7]=int(a/128);
if(b[0]==1){
digitalWrite(0, HIGH);
}else{
digitalWrite(0, LOW);
}
if(b[1]==1){
digitalWrite(1, HIGH);
}else{
digitalWrite(1, LOW);
}
if(b[2]==1){
digitalWrite(2, HIGH);
}else{
digitalWrite(2, LOW);
}
if(b[3]==1){
digitalWrite(3, HIGH);
}else{
digitalWrite(3, LOW);
}
if(b[4]==1){
digitalWrite(4, HIGH);
}else{
digitalWrite(4, LOW);
}
if(b[5]==1){
digitalWrite(5, HIGH);
}else{
digitalWrite(5, LOW);
}
if(b[6]==1){
digitalWrite(6, HIGH);
}else{
digitalWrite(6, LOW);
}
if(b[7]==1){
digitalWrite(7, HIGH);
}else{
digitalWrite(7, LOW);
}
}
void loop(){
unsigned short int b = 0x11000110;
IO07(b);
}