Skip to content

Instantly share code, notes, and snippets.

@futoase
Created December 2, 2013 14:57
Show Gist options
  • Select an option

  • Save futoase/7750692 to your computer and use it in GitHub Desktop.

Select an option

Save futoase/7750692 to your computer and use it in GitHub Desktop.
#define SENSORPIN (0)
#define THRESHOLD (80)
void setup()
{
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}
void loop()
{
int iValue = analogRead( SENSORPIN );
double dDistance = 0.0;
if( THRESHOLD < iValue ) {
dDistance = 6768.0 / (iValue - 3.0) - 4.0;
}
if (0.0 == dDistance) {
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
else if ( 10 > dDistance ) {
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
}
else {
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment