Go Down

Topic: Swap between two applications with Leonardo (Read 259 times) previous topic - next topic

typix

Hi,

I want the Arduino Leonardo to swap between two apps only once.
Here's my code, but it does it in loop although I used a condition.

Code: [Select]
int FLAG = 1;

void setup() {
  // put your setup code here, to run once:
  Keyboard.begin();


}

void loop() {
  // put your main code here, to run repeatedly:
  if(FLAG = 1)
  {
    delay(3000);
    Keyboard.press(KEY_LEFT_ALT);
    delay(1000);
    Keyboard.press(KEY_TAB);
    Keyboard.releaseAll();
  }
  FLAG = 0;
}


Thanks for the help.

MalharD

Murphy always gets me ...

typix

So, What is your problem ?

-Malhar
I want it to do it only once, but it does it in a loop and it swaps between them again and again.

acitta


typix

just put them both in set up
I forgot to mention I need this for another project and I don't want this to be in the setup.

acitta

from http://www.arduino.cc/en/Reference/If

Beware of accidentally using the single equal sign (e.g. if (x = 10) ). The single equal sign is the assignment operator, and sets x to 10 (puts the value 10 into the variable x). Instead use the double equal sign (e.g. if (x == 10) ), which is the comparison operator, and tests whether x is equal to 10 or not. The latter statement is only true if x equals 10, but the former statement will always be true.


You need to make it   if(FLAG == 1)

MalharD

just put them both in set up
like this

Code: [Select]
int FLAG = 1;
void setup() {
   Keyboard.begin();
      
   delay(3000);
    Keyboard.press(KEY_LEFT_ALT);
    delay(1000);
    Keyboard.press(KEY_TAB);
    Keyboard.releaseAll();
  FLAG = 0;
}

void loop() {
  }


It'll run once and stop.
Murphy always gets me ...

typix

from http://www.arduino.cc/en/Reference/If

Beware of accidentally using the single equal sign (e.g. if (x = 10) ). The single equal sign is the assignment operator, and sets x to 10 (puts the value 10 into the variable x). Instead use the double equal sign (e.g. if (x == 10) ), which is the comparison operator, and tests whether x is equal to 10 or not. The latter statement is only true if x equals 10, but the former statement will always be true.


You need to make it   if(FLAG == 1)
Wow I forgot! Thank you very much!

Go Up