I need some help understanding something. First, the code:
int encoder = 4;
unsigned long speed = 0;
void setup()
{
pinMode(encoder, INPUT);
}
void loop()
{
speed = getspeed();
delay(1000);
}
//unsigned long getspeed() // THIS IS WHAT I THOUGHT WOULD WORK
long getspeed() // THIS IS WHAT WORKS
{
unsigned long duration = 0;
duration = pulseIn(encoder, HIGH);
return(duration);
}
I would like to return an unsigned long from function getspeed(), but unless I declare it long it won't compile. I get this error:
In function 'void loop()':
error: 'getspeed' was not declared in this scope
What am I missing here? (In my dreadful ignorance of coding, I should add)
I should add (having just discovered) that the comments in caps must be removed. I added them in the forum post editor - so when I double checked my posted code NOTHING compiled!
That makes sense.
Now that my bot is "hardware complete", it's time to concentrate on code. I brought my K&R to work for lunchtime reading. Those programming classes I took seem long ago and far away!