(SOLVED)What can Arduino do for you bike ?

Hi folks.
I am a touring biker. I also play with Arduino. So how about combine this great things ?.
I look around. There is a great thing they call Stromputer. Also a fine project : Mpguino.
I wanted first of all a precise speedometer with seven segment display. I also wanted to
see the distance and direction. I bought a Arduino, display and en small gps reciver.
Wrote a program with inspiration from differnt source. Works perfectily.
Then i wanted a auto blinker like BMW bike. I wrote som code and it works great.
But now i think the speedo update now is a little slow.
What did i do wrong ?
Is there wayes to update the code ?

Sorry for the danish comment :slight_smile:

Best regards
Soren

I hope this looks ok. It solved the update problem. (Use the Button lib)
Thanks

gps_sbc_blink1.ino (9.45 KB)

dGPS dgps = dGPS();               // Construct dGPS class

Wrong.

dGPS dgps;

Correct.

if ((((dgps.Vel()) *1.9) > 5)&&(((dgps.Vel()) *1.9) < 30)) {
 ledMetro.interval(10000); // if the pin is HIGH, set the interval to 0.25 seconds.
  }

What the code is doing has nothing to do with the comment. You need to make the code match the comment.

void blinker()
  {
 for (int i = 0; i < 100; i++){
   VbuttonState = digitalRead(VbuttonPin);
   HbuttonState = digitalRead(HbuttonPin);
   //debugblink();
  if ((VbuttonState == 0) && (HbuttonState == 0)){     
flash();
delay(500);}

Hmmm, I wonder why updates are slow.

Get rid of the delay(). That is NOT the way to do multiple things at once.

Next time you post code, get rid of commented out code first, AND use Tools + Auto Format. I got dizzy reading as far as I did.

Sorry.
I am very new to this. Very bad to doc things.
=(

I try to delete the delay() but then it is very dif to cancel the blinker. Is there a way to do it ?
Best regards
Soren

gps_sbc_blink1.ino (9.93 KB)

Is there a way to do it ?

Of course. First, read, understand, and embrace the philosophy of the blink without delay example. Then, use ctrl-A and ctrl-X to delete your whole program, and start over. Do not even consider the possibility of using delay().

On any given pass through loop(), you may need to turn the light on. On any given pass, you may need to turn the light off.

You can delegate the responsibility for making that decision, based on the time it is now, the time the light's state was last changed, the light's state, and how many times the light has flashed so far, to a function (and I'd recommend that you do that), but you need to make sure that the function does NOT block. It gets called, it decides if there is anything to do, and it returns, nearly immediately.

Checking the switches to decide whether to quit blinking the turn signals is NOT part of that function.

But that is a problem.
If i stand still with the bike the blink run forever. (If speed is under 5kmt the blink stops after 250m)
So perhaps there is another way ?
(and thaks for involving)
Søren

But that is a problem.

Why is rewriting the program a problem?

If i stand still with the bike the blink run forever. (If speed is under 5kmt the blink stops after 250m)

Well, shouldn't it? If you are stopped, waiting to make a turn, the turn signal should continue to blink. The turn signal should stop blinking only after you've made the turn. Of course, it shouldn't blink forever if you decide not to turn, but, then, you wouldn't be stopped in that case.

So perhaps there is another way ?

There's the tried-and-tested "Live with the problem" way.

The "push both buttoms" thing is a way to cancel without a dedicate cancel buttom. But it is hard to read without delay()
Soren

I have had a look at your code but I can't make sense of it without an explanation of what it is supposed to do and how it is supposed to work.

This demo several things at a time shows how you can time things without using delay(). The code for buttons to change flashing speed in this demo may also be of interest.

...R

Thanks - I struggle on.
You inspire me.
Soren