Arduino Advent Calendar Day 02 - Fade, Flicker and Twinkle

Need help for the Arduino Advent Calendar Day 2 Guide? Just post on this thread and our highly trained team of Arduino ninjas will be able to help you in no time!

There seems to be two types of resistors in the advent calendar pack (Each of 4 sets). Is this correct and if so what are the values.

OK I have found my multi-test meter (at the bottom of the box) and it would appear that
4 of the resistors are 10 ohms (which should be brown black black red if my eyes are correct)
4 of the resistors are 220 ohms (which should be red red brown blue if my eyes are correct)

Is this correct?

How do you turn the program off once it is going? Is there a stop function or button?

Yup there are two types of resistors in the pack. 10K Ohm Resistors (which we’ll use for voltage dividers etc) and 220 Ohm Resistors (for limiting the current going to our LEDs).



Not by specifically. You could program a function that takes the input from a push button and toggles a state in the program. You could then have a “flashing state” and a “non-flashing state” etc

Hi Curiosci

The Loop function is designed to run continuously.
To stop the program from running pull the power/usb.
If you want to control how many times the loop() loops then try these options.

Run loop() once and control number of iterations in program.

  for(int i=0;i<NUM_LOOPS;i++){
    //your code here

Run code whilst button is pressed

    while(digitalRead(BUTTON_PIN)){} //wait for button to be released
    //your code goes here

To run code/program only when button is pressed.
put a NOT in front of digitalRead
i.e '!digitalRead(BUTTON_PIN)

Run code continuously but stop when button pressed (requires reset to restart)

  //your code goes here
    while(digitalRead(BUTTON_PIN)){} //wait for button to be released
      //this while block will run forever

You can also make a button press stop the code/program and then another button press restart it.

Hope this helps

You might want to have a look at the day 5 push button example which has a push button that can toggle state:

Specifically look at:

const unsigned int buttonPin = 7;
const unsigned int ledPin = 13;
int buttonState = 0;  
int oldButtonState = LOW;
int ledState = LOW;
void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState != oldButtonState &&
      buttonState == HIGH)
    ledState = (ledState == LOW ? HIGH : LOW);
    digitalWrite(ledPin, ledState);
  oldButtonState = buttonState;