22 May 2011

SuperBlink

Now that I have had a chance to play around with various INPUTS and OUTPUTS, I think I need to show you some of my own creations. This is what is so good about Arduino. You can easily build from the experience of others, and introduce your own creative flair.

When I got my Arduino out of it's packaging, I did not know how fragile it was, I was so scared that I was going to break it. You'll soon find out that it is not as fragile as it looks, but I tend to treat it like an Egg anyway.

Getting Started:
Before you even plug your Arduino into your computer, you are going to need some software to program the little gizmo. Luckily the software is FREE ! Get it here.

Actually, I would recommend that you read the "Getting Started Guide" at the Arduino Web site: and follow the links for your operating system. I use Windows 7 - so this is the guide that I used - here.
I am not going to repeat all of that information, that would be a waste of time.

If you have read the guide, you would have played with the famous "Blink" program. Now its time to supercharge that sucker.


Blink THIS !!

Here is an Arduino sketch that requires the following components.
  • 10 x LEDs (5 Red, 5 Yellow)
  • 9   x 330 ohm resistors
  • 10 x wires to connect it all together.
The Sketch



The video:


The Arduino Code: (Updated Aug 2014)


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* ========================================================
       Project : SuperBlink
        Author : ScottC
       Created : 21st May 2011
   Description : A super-charged Blink program
============================================================
*/

void setup(){
  //Initialise the LEDPins to OUTPUT
  for(int i=4; i<14; i++){
    pinMode(i, OUTPUT);
  }
}

void loop(){
  redYellow(3);  //3 replicates of the redYellow sequence
  curtain(2);    //2 replicates of the curtain sequence
  fastSlow(2);   //2 replicates of the fastSlow sequence
}

void redYellow(int Reps){
  for(int k=1; k<(Reps+1); k++){
    for(int i=4; i<14; i=i+2){
      blink(i,200,20);              //Call the blink method below
    }
    for(int i=13; i>3; i=i-2){
      blink(i,200,10);              //Call the blink method below
    }
  }
}

void curtain(int Reps){
  for(int k=1; k<(Reps+1); k++){
    for(int j=1; j<257; j=j+j){
      int LEDCounter=1;
      int LEDSwitch=1;
      for(int ledPin=4; ledPin>3 && ledPin<14; ledPin=ledPin+LEDCounter){
        if(LEDSwitch){
          digitalWrite(ledPin, HIGH);
          delay(j);
        }else{
          digitalWrite(ledPin, LOW);
          delay(j);
        }
        if(ledPin>12){
          LEDCounter*=-1;
          LEDSwitch=0;
          digitalWrite(13, LOW);
          delay(j);
        }
      }
    }
  }
}

void fastSlow(int Reps){
  for(int k=1; k<(Reps+1); k++){
    for(int j=1; j<257; j=j+j){
      int LEDCounter=1;
      for(int i=5; i>3 && i<14; i=i+LEDCounter){
        blink(i, j, 10); //Call the blink method below
        if(i>12){
          LEDCounter*=-1;
        }
      }
    }
  }
}


void blink(int LEDPin, int LEDOnTime, int LEDOffTime){
  digitalWrite(LEDPin, HIGH);
  delay(LEDOnTime);
  digitalWrite(LEDPin, LOW);
  delay(LEDOffTime);
}
 

If you like this post please support me here:

1 comment:

Feel free to leave a comment about this tutorial below.
Any questions about your particular project should be asked in the ArduinoBasics forum.

Comments are moderated due to large amount of spam.