Demo entry 1469173

cpp

   

Submitted by anonymous on Mar 16, 2015 at 21:26
Language: C. Code size: 1.2 kB.

#include <Servo.h> // include Servo library 

Servo vertical;   // vertical servo 
int servov = 90;     // stand vertical servo

// LDR pin connections
// name = analogpin;


void setup()
{
  //servo connections
  //name.attach(pin);
 
  vertical.attach(9); 
  vertical.write(servov);
}
void loop() 
{
  int lt = analogRead(0); // top left
  int rt = analogRead(1);
  int ld = analogRead(3); // down left
  int rd = analogRead(2);
  


  int dtimebetween = 250; // 250 milliseconds, used for 
  int dtimeafter = 1000*15*60; // 1 hour in miliseconds
  int tol = 20;
  
  int avt = (lt + rt) / 2; // average value top
  int avd = (ld + rd) / 2; // average value down

  int dvert = lt - ld; // check the difference of up and down
 
  if (abs(dvert) > tol) // check if the difference is in the tolerance else change vertical angle
  {
   if (lt < ld)
    {
      servov = --servov;
      if (servov > 180) 
        servov = 180;
       vertical.write(servov);
   }
   else if (lt > ld)
   {
     servov= ++servov;
     if (servov < 0)
      servov = 0;
      vertical.write(servov);
   }
   

  delay(dtimebetween);
 if(abs(dvert) < tol){delay(dtimeafter);}

}
} 

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).