2个回答
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//在arudino 中调试通过
//将A0,A1,A2,接入IO 4,7,8
//如数据不稳定可以将digitalRead改为digitalReadt程序消抖进行对比。
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //电脑反馈运行状态变量值
#define HC148A0 8
pinMode (4, INPUT);
pinMode (7, INPUT);
pinMode (8, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int a = 0;
Serial.print(" A2 ");
Serial.print("A1");
Serial.print(" A0 ");
int n8 = digitalRead(8);
delay(2);
int n7 = digitalRead(7);
delay(2);
int n4 = digitalRead(4);
bitWrite(a, 0, n4);
bitWrite(a, 1, n7);
bitWrite(a, 2, n8);
Serial.print(n8, BIN); Serial.print(" "); Serial.print(n7, BIN); Serial.print(" "); Serial.print(n4, BIN);Serial.print(" = "); Serial.println(a);
// Serial.println("<------------------------------->");
delay(100);
}
bool digitalReadt(int testpin) {
bool digval = digitalRead(testpin); //消抖
delay(5);
while (digval != digitalRead(testpin)) {
delay(5);
digval = digitalRead(testpin);
delay(5);
}
return digval;
}
//将A0,A1,A2,接入IO 4,7,8
//如数据不稳定可以将digitalRead改为digitalReadt程序消抖进行对比。
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //电脑反馈运行状态变量值
#define HC148A0 8
pinMode (4, INPUT);
pinMode (7, INPUT);
pinMode (8, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int a = 0;
Serial.print(" A2 ");
Serial.print("A1");
Serial.print(" A0 ");
int n8 = digitalRead(8);
delay(2);
int n7 = digitalRead(7);
delay(2);
int n4 = digitalRead(4);
bitWrite(a, 0, n4);
bitWrite(a, 1, n7);
bitWrite(a, 2, n8);
Serial.print(n8, BIN); Serial.print(" "); Serial.print(n7, BIN); Serial.print(" "); Serial.print(n4, BIN);Serial.print(" = "); Serial.println(a);
// Serial.println("<------------------------------->");
delay(100);
}
bool digitalReadt(int testpin) {
bool digval = digitalRead(testpin); //消抖
delay(5);
while (digval != digitalRead(testpin)) {
delay(5);
digval = digitalRead(testpin);
delay(5);
}
return digval;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询