Skip to main content

I need to creatcreate something for a school assignment, but I'm stuck atmat the moment. 
I have one code wich, which makes the arduino leonardoArduino Leonardo press space button on my laptop wich, which works.

I have another code, that turns on the LED when 2 wires are put in water.

Now I want to combine them, but without succesI have no success.

The keyboard code leonardo:

bool eenkeergeweest = false;

#include <Keyboard.h>

void setup() { // make pin 2 an input and turn on the // pullup resistor so it goes high unless // connected to ground: pinMode(2, INPUT_PULLUP); // initialize control over the keyboard: Keyboard.begin(); }

void loop() { // while (digitalRead(2) == HIGH) { // // do nothing until pin 2 goes low // delay(500); // } delay(1000); // new document: if (!eenkeergeweest) { eenkeergeweest = true; Keyboard.print(' '); delay(100); //Keyboard.releaseAll(); }

// wait for new window to open: delay(1000); }

bool eenkeergeweest = false;

#include <Keyboard.h>

void setup()
{
    // make pin 2 an input and turn on the
    // pullup resistor so it goes high unless
    // connected to ground:
    pinMode(2, INPUT_PULLUP);
    // initialize control over the keyboard:
    Keyboard.begin();
}

void loop()
{
    // while (digitalRead(2) == HIGH) {
    //   // do nothing until pin 2 goes low
    //   delay(500);
    //  }
    delay(1000);
    // new document:
    if (!eenkeergeweest) {
        eenkeergeweest = true;
        Keyboard.print(' ');
        delay(100);
        //Keyboard.releaseAll();
    }

    // wait for new window to open:
    delay(1000);
}

The code for the water LED:

int out = 12; int in = 4;

int rd;

void setup()

{

pinMode(out,OUTPUT);

pinMode(in,INPUT);

}

void loop()

{

rd=digitalRead(in);

if(rd==HIGH)

{

digitalWrite(out,HIGH);

delay(100);

}

else

{

digitalWrite(out,LOW);

delay(100);

}

}

Thanks in advance

int out = 12;
int in = 4;

int rd;

void setup()
{
    pinMode(out, OUTPUT);
    pinMode(in, INPUT);
}

void loop()
{
    rd = digitalRead(in);
    if (rd == HIGH)
    {
        digitalWrite(out, HIGH);
        delay(100);
    }
    else
    {
        digitalWrite(out, LOW);
        delay(100);
    }
}

I need to creat something for a school assignment but I'm stuck atm. I have one code wich makes the arduino leonardo press space button on my laptop wich works.

I have another code that turns on the LED when 2 wires are put in water.

Now I want to combine them but without succes.

The keyboard code leonardo:

bool eenkeergeweest = false;

#include <Keyboard.h>

void setup() { // make pin 2 an input and turn on the // pullup resistor so it goes high unless // connected to ground: pinMode(2, INPUT_PULLUP); // initialize control over the keyboard: Keyboard.begin(); }

void loop() { // while (digitalRead(2) == HIGH) { // // do nothing until pin 2 goes low // delay(500); // } delay(1000); // new document: if (!eenkeergeweest) { eenkeergeweest = true; Keyboard.print(' '); delay(100); //Keyboard.releaseAll(); }

// wait for new window to open: delay(1000); }

The code for the water LED:

int out = 12; int in = 4;

int rd;

void setup()

{

pinMode(out,OUTPUT);

pinMode(in,INPUT);

}

void loop()

{

rd=digitalRead(in);

if(rd==HIGH)

{

digitalWrite(out,HIGH);

delay(100);

}

else

{

digitalWrite(out,LOW);

delay(100);

}

}

Thanks in advance

I need to create something for a school assignment, but I'm stuck at the moment. 
I have one code, which makes the Arduino Leonardo press space button on my laptop, which works.

I have another code, that turns on the LED when 2 wires are put in water.

Now I want to combine them, but I have no success.

The keyboard code leonardo:

bool eenkeergeweest = false;

#include <Keyboard.h>

void setup()
{
    // make pin 2 an input and turn on the
    // pullup resistor so it goes high unless
    // connected to ground:
    pinMode(2, INPUT_PULLUP);
    // initialize control over the keyboard:
    Keyboard.begin();
}

void loop()
{
    // while (digitalRead(2) == HIGH) {
    //   // do nothing until pin 2 goes low
    //   delay(500);
    //  }
    delay(1000);
    // new document:
    if (!eenkeergeweest) {
        eenkeergeweest = true;
        Keyboard.print(' ');
        delay(100);
        //Keyboard.releaseAll();
    }

    // wait for new window to open:
    delay(1000);
}

The code for the water LED:

int out = 12;
int in = 4;

int rd;

void setup()
{
    pinMode(out, OUTPUT);
    pinMode(in, INPUT);
}

void loop()
{
    rd = digitalRead(in);
    if (rd == HIGH)
    {
        digitalWrite(out, HIGH);
        delay(100);
    }
    else
    {
        digitalWrite(out, LOW);
        delay(100);
    }
}
Source Link

Combining arduino leonardo code with water alarm code

I need to creat something for a school assignment but I'm stuck atm. I have one code wich makes the arduino leonardo press space button on my laptop wich works.

I have another code that turns on the LED when 2 wires are put in water.

Now I want to combine them but without succes.

Hope someone will help me with this.

These are the codes:

The keyboard code leonardo:

bool eenkeergeweest = false;

#include <Keyboard.h>

void setup() { // make pin 2 an input and turn on the // pullup resistor so it goes high unless // connected to ground: pinMode(2, INPUT_PULLUP); // initialize control over the keyboard: Keyboard.begin(); }

void loop() { // while (digitalRead(2) == HIGH) { // // do nothing until pin 2 goes low // delay(500); // } delay(1000); // new document: if (!eenkeergeweest) { eenkeergeweest = true; Keyboard.print(' '); delay(100); //Keyboard.releaseAll(); }

// wait for new window to open: delay(1000); }

The code for the water LED:

int out = 12; int in = 4;

int rd;

void setup()

{

pinMode(out,OUTPUT);

pinMode(in,INPUT);

}

void loop()

{

rd=digitalRead(in);

if(rd==HIGH)

{

digitalWrite(out,HIGH);

delay(100);

}

else

{

digitalWrite(out,LOW);

delay(100);

}

}

Thanks in advance