Hello everyone, I've come up with a project for this week and I tried to write some code myself but couldn't quite figure everything out.
The idea is as follows:
I've gotten myself a fitness stepper a couple of days ago and I thought about one of those fancy tour the france simulators and I thought why can't I make something like that with this guy? I've already written some code to read it out, the code is as follows:
int switchPin =2; // input pin. actually this is the workout stepper
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int previousState = 0;
void setup() {
pinMode(switchPin, INPUT); // declare pushbutton as input
Serial.begin(9600);
while (!Serial){
}
}
void loop(){
val = digitalRead(switchPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
currentState = 0;
}
else {
currentState = 1;
}
if(currentState != previousState){
if(currentState == 1){
counter = counter + 1;
delay(700);
Serial.println(counter);
}
}
previousState = currentState;
}
Basically what it does is when go from high to low or from low to high (aka. when you take a step) It adds one to the counter so you can read how many steps you've taken from the serial monitor.
So what I want to achieve is when you step in a certain pace the arduino will translate it to the key W which is the "walk" key in most videogames and simulators and if you run a little faster than that it'll translate it to pressing the W key twice which would be the "run" key. Of course when you stop running the arduino will stop telling the computer to run.
I am aware that you need an arduino based on the 32u4 and have gotten myself an arduino/genuino micro.
Any thoughts on how I could make this work?