Quote:
|
Originally Posted by Windward
I am trying to get the code to work with 2 spikes. It works with 1 spike, but I'm still a little confused on how to modify.
Code:
if(initVar != 1)
{
relay2_fwd != relay2_rev;
initVar = 1;
}
if (p1_sw_trig && !oldstate)
{
relay1_fwd = !relay1_rev;
relay1_rev = !relay1_fwd;
relay2_fwd = !relay2_rev;
relay2_rev = !relay2_fwd;
}
if (p1_sw_trig != oldstate)
oldstate = p1_sw_trig;
I initialized the relay2 fwd & rev so it was opposite. Otherwise the code was pretty much the same.
I am not sure where to procede from here.
|
While that may work, It's a bit different then what I had..
Code:
if(initVar != 1)
{
relay2_fwd != relay2_rev;
initVar = 1;
}
if (p1_sw_trig && !oldstate)
{
relay1_fwd = !relay1_fwd;
relay1_rev = !relay1_rev;
relay2_fwd = !relay2_fwd;
relay2_rev = !relay2_rev;
}
if (p1_sw_trig != oldstate)
oldstate = p1_sw_trig;
The NOT (!) operator basically toggles the state of it. If it was 0, it becomes 1. If it was 1, it becomes 0.
If thats confusing consider this:
Code:
char A = 0;
printf("%i",A);
A = !A;
printf("%i",A);
A = !A;
printf("%i",A);
Will result in this output:
0
1
0
I'm not sure if this post will help, or just confuse you more. Let me know if you still don't understand.