I am working on a project to shift gears for a motorcycle engine 6 times both up and down. [0 2 3 4 5 6] 1st gear will be omitted, 0 represent Neutral. I was thinking a possible while loop but i can't envision it currently. So the upshift and downshift buttons needs to be disabled somehow past the specified limits. So any button press greater than 6th gear or Less than 0 (neutral) results in no PinOutput. Is there a way of disabling pins temporarily or a logical way of doing it?
Thanks for any help. Very new to arduino so all help is much appreciated.
i’m thinking you should be able to use the constrain() function.
otherwise you should use old-skool if...then statements like ;
IF var < min THEN var = min
IF var > max THEN var = max var being your gears
you could write a Function or Class (library) to handle which gear your are in.
for example if you write a class called Gear for example with some methods called:
up - for going up the gear.
down - for going down the gear
getGear - returns current gear
lastGear - returns last gear
gearChanged - true / false if gear has changed or not
you could use it like so:
#include<Gear.h>;
Gear myGear(6); Â // Create an instance of gear with maximum gears of 6.
myGear.up(); Â Â Â Â Â Â Â // go up a gear.
myGear.Down(); Â Â Â // go down a gear.
myGear.getGear(); Â // returns int of current gear.
myGear.lastGear(); Â // returns last selected gear.
myGear.gearChanged(); // returns a boolean true or false (0 / 1)
int x;
x = myGear.getGear();
if (x == someValue && myGear.gearChanged() == true;){
 // Do something
}
etc and so-forth
I’ve included a sample library to get you started (if you wish) you can alter it to include the code you want to execute for example make the library go up and down the physical gears, this would let you make a method that can select a gear instead of going up and down or you can use it as is and compare the value of the gear to execute the code for actually changing the gear.