Finding a source of light


i doing project have find , follow light. can follow light no problem once starts off in right direction have trouble detecting light orientation (given robot can placed in direction start).
i can use ldr's , have tried doing full 180 degree turn, making note of highest intensity , going it, code doesn't seem work.

#include <orangutanlcd.h>
#include <orangutanmotors.h>

int motor_speed = 70;
int left_ldr=6;
int right_ldr=7;
int x=analogread(left_ldr);
int y=analogread(right_ldr);
int starttime;
int currenttime;
int newintensity;
int highestintensity = 1500;
int timespinning;
int highesttime;
int z;

void setup()
{
  clear();
  void motors_init(void);
 
  delay(1000);
  set_motors(motor_speed,-motor_speed);
  starttime = millis();
  currenttime = starttime;
  while((currenttime-starttime)<1650)
  {
    newintensity = ((analogread(left_ldr) + analogread(right_ldr))/2);
    if(newintensity <= highestintensity)
    {
      highestintensity = newintensity;
      timespinning = millis();
    }
    currenttime = millis();
  }
  highesttime = timespinning - starttime;
  print_long(highesttime);
  delay(highesttime);
  set_motors(40,40);
}

is there thing wrong code or have better possible solution method? working pololu 3pi.

thanks!

quote
is there thing wrong code

besides being posted incorrectly? yes, isn't complete.

why there function prototype defined in setup()?
where clear()?
where loop()?


Arduino Forum > Topics > Robotics (Moderator: fabioc84) > Finding a source of light


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support