Quick Shifter Advice

Hi.

Im new to the arduinos and are very interested wt learning how to use these devices. I have just got a kit the other day and have a book that has some basic help in it. Im looking at building a quickshifter circuit for my ZXR 400, my plan is to use a pressure sensitive resistor to be in the shift rod and make tue arduino watch the resistance change. then when i see whats a sensible reading make it trip the ignition for x amount of seconds. Is this a fairly straight forward circuit to have a go at building. Does anyone know a good place for me to look at setting up a "if" function. I thought whilst coding i was going to use a potentiometer and a led that is on constant until it sees "shift"
Im well up for learning how to do it myself just wanted people to say if theres a good place to read to make it more understandable and also aky advice if anyone has already built a circuit like this.

Many thanks Adam

Sounds like a good starting Point. If I were to get really technical, an if is not a "function", it is a "conditional branch". If the condition in the if Statement evaluates to true, the code within the if Statement is executed, otherwise, the program will skip over (branch) to the end of the code within the if Statement. A function on the other Hand is a sub-Routine which Returns a value, such as the millis() function. In C, that value is oftion nothing, a void. Ok, so I am a Computer nerd. You're on the right track. Good luck!

Tricey27:
Does anyone know a good place for me to look at setting up a "if" function.

Apart from the silly answer "somewhere in your program" that question is impossible to answer without seeing your program code.

And please use the code button </>so your code looks like thisand is easy to copy to a text editor

Is it your intention just to use the Arduino to manage the engine during a normal foot-operated shift?

I wonder if turning the engine off completely is the proper solution? I have never ridden a bike but in a car one just adjusts the throttle during a shift first to reduce the loading on the gears while they move into neutral and then to match the engine speed to the speed required by the new gear position so that they mesh cleanly.

...R

I remember at least one gear shifter project discussed in the forum this year. Search the forum for more inspiration.

Thanks for answers people. Had a quick play last night and have a very basic code set at the moment. Was reading about the "if, else" condition. This should cover what im trying to figure at the moment fairly well. Ill upload my current very simple code below. So I now have a LED that is illuminated constant until it sees the analog input going about 500 that I want it to cut the light for x amount of seconds. I need it so that when it does see this it will send LED low for the time then go back HIGH. As it stands now when I go above it goes LOW and below it goes high but if I stay above 500 it stays off. How can I make this just go off then wait until it sees a <500 signal before allowing it to come back LOW again and do another cycle.

The reason I am after this is so you can perform "Flat out shifting" meaning the quickshifter kills ignition for what should be somewhere around 0.075 seconds just to allow the bike to drop into gear.

Any help in hugely appeciated.

Adam

<

// these constants won't change:
const int ignitionLed = 13;
const int analogPin = A0;
const int threshold = 500;

void setup() {
//initialise the led as a output:
pinMode(ignitionLed, OUTPUT);
// initialise serial communication:
Serial.begin(9600);
}

void loop() {
// read value of potentiometer:
int analogValue = analogRead(analogPin);

// if value is high enough turn led off
if (analogValue > threshold) {
digitalWrite(ignitionLed, LOW);
delay(75);
} else {
digitalWrite(ignitionLed, HIGH);

}

// print the serial comms:
Serial.println(analogValue);
delay(1);

}

// these constants won't change:
const int ignitionLed = 13;
const int analogPin = A0;
const int threshold = 500;


void setup() {
  //initialise the led as a output:
  pinMode(ignitionLed, OUTPUT);
  // initialise serial communication:
  Serial.begin(9600);
}


void loop() {
// read value of potentiometer:
int analogValue = analogRead(analogPin);

// if value is high enough turn led off
if (analogValue > threshold) {
  digitalWrite(ignitionLed, LOW);
  delay(75);
} else {
  digitalWrite(ignitionLed, HIGH);
  
}

// print the serial comms:
Serial.println(analogValue);
delay(1);

}

I suspect part of the problem is that you turn the LED off if the value is high wheras you should turn it off only when it changes from low to high.

That means you need a variable to record the previous reading - something like

prevAnalogValue = analogValue; // save old value
analogValue = analogRead(analogPin);
if (analogValue > threshold && prevAnalogValue < theshold) {
  // turn light off etc
}

You may also find problems using delay() as it blocks the Arduino from doing other things. Have a look at how millis() is used to manage timing without blocking in several things at a time

...R

Thanks for your help.

Sorry about this still learning about this coding, do i put that code you have sent me in the loop or setup sorry? Does i need to put prevanalogValue in the integers somewhere as when I try and verify it, it says "was not declared in scope

Many thanks

Adam

It must go in loop() in the place where your code switches off the the LED.

Yes, you need to create the variable prevAnalogValue. It may be simpler to create all the variables before the setup() function - that way they will retain their values when loop() repeats. Alternatively create them inside loop() with the "static" prefix

...R