Noob question... Code to switch LED on or off

I know this is as basic as it comes.

I got the Arduino starter pack today and have never used code before.

Anyways, I'm trying to learn the basics and can now write the very basic code to make an LED blink and know what's doing what.

I'm trying to make a point of understanding and remembering all this stuff instead of just copying and pasting examples. So far, so good.

Now I would like to add a momentary switch, so I can start the LEDs blinking or switch them off when I like. To clarify, I mean to switch on or off the sequence, not to control or interfere with the original blinking when it's on.

Could someone please add on to this very basic code, so I can see what's what? I should be able to get an idea of what's going on when I see the code.

Thank you :slight_smile:

int redLED = 2;
int blueLED = 3;
int greenLED = 4;

void setup()
{
pinMode(redLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}

void loop()

{ digitalWrite(redLED, HIGH);
delay(30);
digitalWrite(redLED, LOW);
delay(30);
digitalWrite(blueLED, HIGH);
delay(30);
digitalWrite(blueLED, LOW);
delay(30);
digitalWrite(greenLED, HIGH);
delay(30);
digitalWrite(greenLED, LOW);
delay(30);
}

I know you're supposed to add notes and stuff... I'm just experimenting and getting in to this whole new alien world.

Specifically: http://arduino.cc/en/Tutorial/Button

From that, you should be able to expand/tweak it to work with a momentary switch.

I'm trying to make a point of understanding and remembering all this stuff instead of just copying and pasting examples.

This is an excellent approach. There are some great tutorials and manuals available online, to help in this regard.

http://www.earthshineelectronics.com/files/ASKManualRev4.pdf is one.