Author Topic: code Q's  (Read 1616 times)

0 Members and 1 Guest are viewing this topic.

Offline ed1380Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,478
  • Helpful? 3
code Q's
« 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;
}
« Last Edit: February 21, 2008, 05:32:12 PM by ed1380 »
Problems making the $50 robot circuit board?
click here. http://www.societyofrobots.com/robotforum/index.php?topic=3292.msg25198#msg25198

Offline frank26080115

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: code Q's
« Reply #1 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
}
« Last Edit: February 21, 2008, 05:42:58 PM by frank26080115 »

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: code Q's
« Reply #2 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)

Offline ed1380Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,478
  • Helpful? 3
Re: code Q's
« Reply #3 on: February 21, 2008, 07:57:16 PM »
thanks.

took some fiddling around but it worked

Problems making the $50 robot circuit board?
click here. http://www.societyofrobots.com/robotforum/index.php?topic=3292.msg25198#msg25198

Offline ed1380Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,478
  • Helpful? 3
Re: code Q's
« Reply #4 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;
}
}
« Last Edit: February 26, 2008, 04:38:28 PM by ed1380 »
Problems making the $50 robot circuit board?
click here. http://www.societyofrobots.com/robotforum/index.php?topic=3292.msg25198#msg25198

 


Get Your Ad Here

data_list