Society of Robots - Robot Forum

Software => Software => Topic started by: ed1380 on February 21, 2008, 05:27:11 PM

Title: code Q's
Post by: ed1380 on February 21, 2008, 05:27:11 PM
since i finally got my programmer working i'm beginning to have perplexing problems with the code part of things.

heres the code I'm working with now. just basically the $50 robot code.

with it I'm able to get the led to light up for one second. good. what's what i want except why isnt it looping and blinking?

"return 1" and "return 0" doesnt make a diference. "loop" causes build errors

Code: [Select]
//SoR Include
#include "SoR_Utils.h" //includes all the technical stuff

int main(void)
{

configure_ports(); // configure which ports are analog, digital, etc.

/*********ADD YOUR CODE BELOW THIS LINE **********/

PORT_OFF(PORTD, 4); //turns led on
delay_cycles(23000); // one second delay
PORT_ON(PORTD, 4); //turns led off
 
/*********ADD YOUR CODE ABOVE THIS LINE **********/

return 0;
}
Title: Re: code Q's
Post by: frank26080115 on February 21, 2008, 05:42:00 PM
you are not telling it to loop so why would it loop?

loops are supposed to be done by using

Code: [Select]
while(1){
//code in here
}
Title: Re: code Q's
Post by: paulstreats on February 21, 2008, 05:45:27 PM
put it inside a while loop

while(1){

//code to be looped here

}

the return doesnt work because its used for a different purpose (returning a value - not returning to a point in the program)
Title: Re: code Q's
Post by: ed1380 on February 21, 2008, 07:57:16 PM
thanks.

took some fiddling around but it worked

Title: Re: code Q's
Post by: ed1380 on February 25, 2008, 10:40:23 PM
well i got more problems.

I'm finally able to get the wanted pins to work. kinda. it goes. 0,1,2,3,3,2,1,0,0,0,0,0,0,0,etc

i used this to get it
up=0
down=3
 
Code: [Select]
if(up<=3)

{
PORT_ON(PORTD, up);

delay_cycles(8000);

PORT_OFF(PORTD, up++);

delay_cycles(8000);
}

else
{

PORT_ON(PORTD, down);

delay_cycles(8000);

PORT_OFF(PORTD, down--);

delay_cycles(8000);
}


}

fine that'll do, but i  want to do it with the FOR loop. but i cant get it to go past 0,0,0,0,0

EDIT:
BOOYA got it to work. guess all i needed was some sleep
Code: [Select]
while(1)
{




for(int up = 0; up<=3; up++)

{
PORT_ON(PORTD, up);

delay_cycles(1000);

PORT_OFF(PORTD, up);

delay_cycles(1000);
}

for(int down = 3; down<=3;down--)

{
PORT_ON(PORTD, down);

delay_cycles(1000);

PORT_OFF(PORTD, down);

delay_cycles(1000);

if(down == 0)
break;
}
}