Go Down

Topic: cruise control on motorcycle, need to read timing between wheel RPMs on reed swi (Read 3 times) previous topic - next topic

PaulS

Quote
I have test rode it and it works without flaw.

Have you fixed those recursive calls to loop()? If not fundamentally flawed and works without flaw are not compatible.

wildbill

Consider buying another arduino and building a motorcycle simulator for your project. That way you can test your code without having to put yourself at risk. An SD card to record telemetry data would be handy for debugging too.

But seriously, leave this and build up your expertise with some safer projects first.

PeterH


The only failure it can have is to lose power and throttle down.


I don't think you understood the point of my question.

Assume that the Arduino does anything that the hardware is capable of doing - at the worst possible time. Assume that any wire could fall out, any electronic component could fail, any piece of code could do something that you never intended or expected. So, whatever actuator you're using could be commanded to do something completely wrong, in the worst way, at the worst time.

Given that situation, does the rider have a practical and easy means to override the cruise control and kill the power? (If your bike has a clutch, that might be your solution - but not all bikes do.)
I only provide help via the forum - please do not contact me for private consultancy.

msumrell

Peter, as I already replied, yes there are safety overrides that kill the arduino which alows the return spring to pull the throttle closed.

I have several arduinos and am bench testing as I go, or should I say kitchen table testing.

As far as the recursive calls to loop()?, I think this was how I was able to get it to work but I will remove them and see. thanks,

Let me ask my question differently. How would I write the code to sense the reed switch close, count the millis before it closes again (one revolution)? If I need to sense it more than once I will address. I am just asking for help with the code.

ash901226

i have this piece of code that maybe you could tinker with, what it does is if you press a switch that is connected to pin 2 on the arduino board, like so

pin2------|/|-----Ground

the code will measure how long the switch was press and will light up the on board led (pin 13) the same amount of time that the switch was press after the switch was release

Code: [Select]
uint8_t Switch = 2;
uint8_t Led =13;

boolean LedState =LOW;
int SwitchState =0;
int SwitchDebounce;
int LastSwitchState=HIGH;
int LastSwitchDebounce=LOW;

unsigned long LastDebounceTime = 0;
unsigned long DebounceDelay = 50;
unsigned long TimeRelease=0;
unsigned long TimePress=0;

void setup()
{
  pinMode(Switch,INPUT);
  digitalWrite(Switch,HIGH);
  pinMode(Led,OUTPUT);
  digitalWrite(Led,LOW);
}

void loop()
{
  int CurrentSwitch = digitalRead(Switch);
  if (CurrentSwitch != LastSwitchDebounce)
  {
    LastDebounceTime = millis();
  }
  if ((millis() - LastDebounceTime) > DebounceDelay)
  {
    SwitchState = digitalRead(Switch);
    if (SwitchState != LastSwitchState)
    {
      if(SwitchState)
      {
        TimeRelease=millis();
        digitalWrite(Led,HIGH);
      }
      if (!SwitchState)
      {
        TimePress=millis();
      }
      LastSwitchState=SwitchState;
    }
  }
  if ((millis()-TimeRelease)>=(TimeRelease-TimePress))
  {
    digitalWrite(Led,LOW);
  }
  LastSwitchDebounce = CurrentSwitch;
}


Go Up