|
setup diary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void setup() {
// put your setup code here, to run once:
digitalWrite(A0,LOW);
pinMode(A0,OUTPUT);
pinMode(A1,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
signed long v=0;
while(digitalRead(A1)>0);
for(char i=0;i<24;i++){
digitalWrite(A0,HIGH);
delayMicroseconds(5);
v<<=1;
if(digitalRead(A1)>0)v++;
digitalWrite(A0,LOW);
delayMicroseconds(5);
}
digitalWrite(A0,HIGH);
delayMicroseconds(5);
digitalWrite(A0,LOW);
delayMicroseconds(5);
if(v>=1<<24)v|=0xff000000;
Serial.println(v);
delay(1000);
}