Arduino skipping part of "loop()"


hi everybody,

i don't know why arduino keeps on skipping instruction (highlighted in code)...   :-/
...can please?

thanks much!


code: [select]

//variables
int volatile pos = 0;
int sensepin = 3;


void setup() {
 pinmode(13, output);
 attachinterrupt(sensepin-2, out, change); /handles encoder interrupt , update position
 pos=0;
 delay(500);
}

void loop() {
 digitalwrite(13, high);
 delay(500);
 digitalwrite(13, low);
 delay(2000);

 //drive motor in 1 direction until encoder says "-360"
 drivebothto(120,0,-360);   // <<<<<<< skipped <<<<<<<<<


 digitalwrite(13, high);
 delay(500);
 digitalwrite(13, low);
 delay(2000);  

 drivebothto(0,120,360); //not skipped
 
 delay(1000);
 for(int i=0; i<5; i++) {
   digitalwrite(13, high);
   delay(200);
   digitalwrite(13, low);
   delay(200);
 }
 
 digitalwrite(13, low);
 while(1);
}


void stopandwait(int time) {
 //stop
 //motor 1
 analogwrite(10, 0);
 analogwrite(11, 0);
 //motor 2
 analogwrite(6, 0);
 analogwrite(9, 0);
 if(time>0) delay(time);
}

void drivebothto(int one, int two, int theta) {
 
 //motor 1
 analogwrite(10, one);
 analogwrite(11, two);
 //motor 2
 analogwrite(6, one);
 analogwrite(9, two);
 while(pos<theta) delay(1);
 
 stopandwait(0);
}

void out() {     //handles encoder interrupt , update position
 int val2 = digitalread(2);
 int val3 = digitalread(3);
 if ((val2==low && val3==high) || (val2==high && val3==low)) {
   pos++;
   //digitalwrite(13, high);
 }
 else {
   pos--;
   //digitalwrite(13, low);
 }
}

hi

i think int can use positive numbers, think must use long int?

check reference page more info.

lee


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Arduino skipping part of "loop()"


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