Light two LEDs using the Laptop Keyboard

I need some help for a homework in Arduino.

I have to light a YellowLed(pin 13) by pressing the ButtonA (Pin 14) and the key "G" from the Keyboard.

Or turn the RedLed(pin 17) On by pressing the ButtonA and the Key "R" from keyboard.

I am not so good at programming and I have searched everywhere and I can not find a good solution to work.

Is it possible?

TheTiger13:
I have searched everywhere and I can not find a good solution to work.

Of course you won't: that would mean that everything anyone ever wants to do, has been done and documented. Like a civil engineer throwing his hands up because he can't find the plans for the bridge he needs to build.

So show what you tried so far.

Here's an example of how a button can light a led, for starters.

#define ledGalben 13
#define buttonA 14
#define ledRosu 17
#include "Keyboard.h"


void setup()
{
Serial.begin(9600);
  pinMode(ledGalben, OUTPUT);
  pinMode(ledRosu, OUTPUT);
  pinMode(buttonA, INPUT);
Serial.println("Apasa R pentru a aprinde LED-ul Galben si G pentru ledul Rosu!!!");
}

void loop()
{
if (Serial.available())
{
int ch = Serial.read();
Serial.print(ch);

if (ch==71 && buttonA == HIGH)
{
digitalWrite(ledGalben, HIGH);
} else {
  digitalWrite(ledGalben, LOW);
}

if (ch==82 && buttonA == HIGH)
{
digitalWrite(ledRosu, HIGH);
} else {
  digitalWrite(ledGalben, LOW);
}
}
}

O....k so you had code all along :wink:

So say what works and what doesn't work with it...

(Also can you go edit that post and tag the code [code] sketch goes here [/code]

I don't know if it works. I do not have the Arduino. We have it only at school(once/week). And I have to code without knowing the results.

OK, a number of things come to mind here.

One is that you need (as always) to detail your project - explain exactly what is connected to what?

Part of the problem is knowing what program is running on the laptop as it is not as simple as pressing single keys, the serial monitor requires you to type text and hit "Enter" IIRC.

Now my next question is - this homework is not only set for you, is it surely? Exactly what is the expectation?

I presume you have your laptop with you that you take to school and use to program the Arduino, so the IDE is already on your machine with the code. Two things follow; one is that you need to Auto-Format your code (Shorthand: Control-T) on each revision.

The other is that you have made the effort to come here to learn and to solve your problem. Given enough information we can help you but you are badly hampered by limited access to - the Arduino. I deduce that you really are interested in Arduinos and suggest that looking to the future - including your current course though a delay is involved - you get your own Arduinos to work with.

On eBay, Arduino Nanos ("clones") - the version you should be using, not a UNO - cost about US$3. You want two to start with for various reasons. You likely could want an inexpensive "starter kit" or for economy, buy parts piecemeal. For the current matter, you want a MB-102 "breadboard", a pack of 65 coloured jumper wires, a pack of push-buttons, LEDs, then a resistor assortment (values 50 Ohm to 100k at least). Others may add to this. I suggest you order some now and if they take 3 weeks to get from China as they may, that will only be another two weekly sessions before you are equipped.

You need someone to teach and help you soldering.