This bunch of code gives me 6 errors upon attempt to compile. Basically it's a 'nightrider' (or whatever the internet calls it nowadays) thingy which flashed LEDs from LED0 to LED7 and then back in a sequential order . The only modification is that I have 2 buttons which manually change the direction of flashing .
There is a left button and a right button . If the pattern is progressing to the right and I press the left button , then it changes direction to the left starting from the led that was active when I pressed the button . If I press the right button while it's travelling right then nothing happens .
Vice versa for the other side.
Can someone just skim through that and tell me if there are any coarse syntax errors or whatever that cannot be done the way I did it , i'd appreciate it.
I'm using Atmel studio 6. It tells me I have 6 errors but It doesn't show me where they are.
Thanks in advance
I've had some experience in C++ and java in the past but some things confuse me here.
Why do I see functions declared in some tutorials and others just omit it? Does it depend on the compiler or something?
There is a left button and a right button . If the pattern is progressing to the right and I press the left button , then it changes direction to the left starting from the led that was active when I pressed the button . If I press the right button while it's travelling right then nothing happens .
Vice versa for the other side.
Rich (BB code):
#include <avr/io.h>
#include <util/delay.h>
int x=0;
int y=0;
int roamleft(int x);
int roamright(int y);
DDRB = 0b11111111;
DDRD = 0b00000011;
PORTD = 1<<PIND2 | 1<< PIND3;
int main(void)
{
while(1)
{
x = roamright(y); // flash to the right sequentially from LED Y to LED 7
y = roamleft(x); // flash to the left sequentially from LED X to LED 0
}
}
int roamright(y)
{
for(x=y;x<8;x++) // cycles through the LED ports
{
PORTB = 1 << x; // Flash the led
_delay_ms(100); // delay before flashing next led
PORTB = 0; // Turn LED port off
if(bit_is_clear(PIND,2)) // Test if button pressed
{
return x; //break the cycle and call 'roamleft' carrying in the value that the led stopped at.
}
}
return x; // if button is not pressed , then x=7 will be carried into 'roamleft' so it starts to flash to the left sequentially starting from LED 7
}
int roamleft(x)
{
for(y=x;y>=0;y--)
{
PORTB = 1 << y;
_delay_ms(100);
PORTB = 0;
if(bit_is_clear(PIND,3))
{
return y;
}
}
return y;
}
Select All
I'm using Atmel studio 6. It tells me I have 6 errors but It doesn't show me where they are.
Thanks in advance
I've had some experience in C++ and java in the past but some things confuse me here.
Why do I see functions declared in some tutorials and others just omit it? Does it depend on the compiler or something?