What type to pass to _delay_ms


i'm using studio 7 ver 7.0.1006 , come error

__build_avr_delay_cycles expects compile time integer constant.

snippet works when inline _delay_ms (), put in function, won't build.

code: [select]
#define f_cpu 16000000l
#define led (1 << pinb4)

#include "avr/io.h"
#include "util/delay.h"

void wait ( uint32_t msec) {
_delay_ms( msec );
}

int main (void) {
int count = 10;

ddrb = (1 << pinb4) | (1 << pinb5);
portb = ~(1 << pinb5);

while (count) {
portb = led;
wait(  350 );
portb = ~led;
wait( 500 );
count--;
}
}


i don't know else except echo error message @ you, tells problem is. parameter _delay_ms() must constant value can calculated @ compile time. when have wrapped function, you're passing variable, not constant. when inlines it, passing literal values 350 , 500, satisfy requirements.


Arduino Forum > Using Arduino > Programming Questions > What type to pass to _delay_ms


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'