int sensorPin = 4;
long result = 0;
int LEDpin = 9;
void setup()
{
Serial.begin(9600);
Serial.println("start");
}
void loop()
{
//Serial.println( RCtime(sensorPin) );
//delay(10);
pinMode(LEDpin, OUTPUT);
if(RCtime(sensorPin)<1500){
digitalWrite(LEDpin,HIGH);
Serial.println("You are lying");
}
else if (RCtime(sensorPin)>=1500){
digitalWrite(LEDpin,LOW);
Serial.println("You are honest");
}
}
long RCtime(int sensPin){
long result = 0;
pinMode(sensPin, OUTPUT); // make pin OUTPUT
digitalWrite(sensPin, HIGH); // make pin HIGH to discharge capacitor - study the schematic
delay(1); // wait a ms to make sure cap is discharged
pinMode(sensPin, INPUT); // turn pin into an input and time till pin goes low
digitalWrite(sensPin, LOW); // turn pullups off - or it won't work
while(digitalRead(sensPin)){ // wait for pin to go low
result++;
}
return result; // report results
}
Circuit:
long result = 0;
int LEDpin = 9;
void setup()
{
Serial.begin(9600);
Serial.println("start");
}
void loop()
{
//Serial.println( RCtime(sensorPin) );
//delay(10);
pinMode(LEDpin, OUTPUT);
if(RCtime(sensorPin)<1500){
digitalWrite(LEDpin,HIGH);
Serial.println("You are lying");
}
else if (RCtime(sensorPin)>=1500){
digitalWrite(LEDpin,LOW);
Serial.println("You are honest");
}
}
long RCtime(int sensPin){
long result = 0;
pinMode(sensPin, OUTPUT); // make pin OUTPUT
digitalWrite(sensPin, HIGH); // make pin HIGH to discharge capacitor - study the schematic
delay(1); // wait a ms to make sure cap is discharged
pinMode(sensPin, INPUT); // turn pin into an input and time till pin goes low
digitalWrite(sensPin, LOW); // turn pullups off - or it won't work
while(digitalRead(sensPin)){ // wait for pin to go low
result++;
}
return result; // report results
}
Circuit:
No comments:
Post a Comment