Delta_G:
How do you figure?
Let's say old is 0, theValue is 1, and the new value is 2.
So we say theOldValue = theValue. So that puts 1 into theOldValue.
Then AFTER that we say theValue = theNewValue, so that puts 2 into theValue. It doesn't do anything to theOldvalue, theOldValue isn't even mentioned on that line. It's not going to go back a line and do something. Code runs from top to bottom, line by line.
What part of the if statement confuses you? Don't ever tell me you don't understand something without either asking a question or explaining what part you don't get. Just, "I don't understand" is a useless and worthless statement. If you tell someone WHAT you don't understand then they can help you.
If I write, someVariableName = someNumber;
then that assigns whatever value is on the right side of that equals to whatever is on the left. In this case if someNumber is 5 then this will set someVariableName to 5. It is really quite simple. So again, you're going to have to elucidate what part confuses you.
If i use this then it doesn't tell arduino that the last switchState was G?
switchStateG = mode 2
switchStateH = mode 1
I don't know what you mean. Arduino doesn't just keep up with stuff you don't tell it to.
These lines say that switchStateG is now whatever value was in mode2 and switchStateH is whatever value was in mode1 at the time these lines were called. That's all that says.
the part of the IF statement i don't understand is if you ad multiple ELSE after each other, does that work or am i limited to just an IF and ELSE?
i have been searching the web and reading allot of stuff and i think i understand the variables now
i came up with a code with a fake pin so i could change the variable of it but it does't always detect the change of the variable
#include <Keyboard.h>
const byte switchPinG = 8;
const byte switchPinH = 9;
byte oldSwitchStateG = HIGH; // assume switch OFF because of pull-up resistor
byte oldSwitchStateH = HIGH; // assume switch OFF because of pull-up resistor
int switchState = LOW; // current state of the switch
const byte switchPin = 11;
void setup ()
{
Serial.begin (115200);
pinMode (switchPinG, INPUT_PULLUP);
pinMode (switchPinH, INPUT_PULLUP);
Keyboard.begin();
} // end of setup
void loop ()
{
// see if switch G is OFF or ON
byte switchStateG = digitalRead (switchPinG);
switchState = digitalRead (switchPin);
// has it changed since last time?
if (switchStateG != oldSwitchStateG)
{
oldSwitchStateG = switchStateG; // remember for next time
delay (debounceTime); // debounce
if (switchStateG == LOW)
{
Keyboard.print("g");
Keyboard.print("g");
digitalWrite(switchPin, HIGH);
} // end if switchStateG is LOW
} // end of state change
// see if switch H is OFF or ON
byte switchStateH = digitalRead (switchPinH);
switchState = digitalRead (switchPin);
// has it changed since last time?
if (switchStateH != oldSwitchStateH)
{
oldSwitchStateH = switchStateH; // remember for next time
delay (debounceTime); // debounce
if (switchState == HIGH)
{
Keyboard.print("");
digitalWrite(switchPin, LOW);
} // end if switchStateH is LOW
else if (switchState == LOW && switchStateH == LOW)
{
Keyboard.print("h");
}
else if (switchState == LOW && switchStateH == HIGH)
{
Keyboard.print("h");
Keyboard.print("h");
}
} // end of state change
}
in this code i use switchStateH for mode 1 and switchStateG for mode 2
when i cycle from 0 to 1 it sends out the letter H. when i cycle from 1 to 2 it sends out the letter H twice. when it is on mode 2 it sends out the letter G twice. and when i cycle it from 2 to 1 it does nothing. but here is the problem when i cycle it from 1 to 0 it should send out the letter H twice but it doesn't detect the change in the variable it should have done when the switch returned to mode 1
{
Keyboard.print("");
digitalWrite(switchPin, LOW);
} // end if switchStateH is LOW
here it should change the variable back to LOW but it doesn't read it after that