Why does this not loop? please!!


can tell me why sketch not loop , detect changes in light levels - please!! delays in loop servo slow down repositioning , works way if can main loop work.

code: [select]
// controlling servo position using potentiometer (variable photoresistor)


#include <servo.h>
servo myservo;  // create servo object control servo

int potpin = 0;  // analog pin used connect potentiometer
int val;    // variable read value analog pin
int valold;  //updates val

void setup()
{valold=90;
myservo.attach(9);  // attaches servo on pin 9 servo object
}

void loop()
{  
 val = analogread(potpin);            // reads value of potentiometer (value between 0 , 1023)
 val = map(val, 0, 1023, 0, 179);     // scale use servo (value between 0 , 180)

if (val > valold);
 for (val=valold; val!=valold; val++)
 {myservo.write(val); delay (150);}
 
if (val < valold);
 for (val=valold; val!=valold; val--)
 {myservo.write(val); delay (150);}

(valold=val);

delay (3000);

           
}

code: [select]
if (val > valold);


val , valold compared. if val greater valold, nothing happens.

code: [select]
for (val=valold; val!=valold; val++)


the body of code executed once. move servo position.

then have nothing statement, followed block body executed once, in move servo same position in.

then, have this:

code: [select]
(valold=val);


what parentheses for? don't hurt anything, but, don't anything, either (except scream newbee).

look @ example in servo library. moves servo based on potentiometer setting.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Why does this not loop?  please!!


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums