About Me

My photo
They never fall who never climb.

012 ARRAY BASED CONTROL OF LED FLASH SEQUENCE


012 ARRAY BASED CONTROL OF LED FLASH SEQUENCE

March 4, 2011    (See also Companion Blog )
[Go BACK to Table of Contents] [ Next Experiment ] [ Last Experiment ]

           I needed to run this circuit to show that I was not messing up either the programming or wiring when things got complicated. The idea here was to flash a series of LEDs in sequence and make them display interesting patterns. If you examine this photo, you can actually see three of the four green LEDs lit up, but fading toward the left behind the jumble of wires. Adding many more LEDs is not that complicated.


Theory:
          By assigning pin configurations using a (single-dimension) array, one should be able to control the off-on sequences of LEDs to display interesting patterns. The LEDs are arranged in a single row on the breadboard. The progress represented by this circuit is that the LEDs can be controlled without resorting to capacitors and relays.

          The two patterns I am after is the chase, one LED after another, and the loop, flashing back and forth.

Practice:
          It worked perfectly the first time. However, this was expected for two reasons. First, the circuit is really just a single circuit duplicated four times, and it could be duplicated many more, but I ran out of resistors. Two, if you examine the code below, you will see it is an array, something I can do in my sleep, having programmed my first array ten years before the PC was invented.

Conclusion:
           LED arrays are easy and not a challenge for me. However, LEDs are not the same as LCD displays, and I can already see that the limited number of output pins on the Arduino means eventually you must use arrays to control arrays, and that can get complicated.
           Later I was able to expand this layout into as many different patterns and LED combinations I could think of. I may not pursue LEDs for now, as arrays are so rudimentary for me that I don’t learn anything. One notable revelation is I now realize where all those simple electronic gadgets come from, like flashing bicycle lights. They represent the easiest type of array programming.

           Here is the breadboard:
           Here is the code:

/* Today is March 04, 2011
* Experiment "Minutes 012" LED array
* Adapted from various sources to match my equipment
* See below to cross-reference (my) files
*/

////////////////////////////////////////////////
//INITIALIZATION AND VARIABLES
// Create the array
int LEDpins[] = {2,3,4,5};
// note the array assignment as follows
// LED #0 is connected to pin 2
// LED #1 is connected to pin 3
// LED #2 is connected to pin 4
// LED #3 is connected to pin 5
int vDelayTime = 100;

///////////////////////////////////////////////
// Begin Main Program
//////////////////////////////////////////////

// This loop steps through the array LED numbers
// Note, it does not step through the PIN numbers
void setup()
{
for (int i = 0; i < 4; i = i + 1)
{
pinMode(LEDpins[i], OUTPUT);
}
}

//The following loop calls the subroutine
//If it wasn't called, the subroutine would only run once
void loop()
{
LightsInSequence();
}

// Here is the subroutine
void LightsInSequence()
{
digitalWrite(LEDpins[0],HIGH);
delay(vDelayTime);

digitalWrite(LEDpins[1],HIGH);
delay(vDelayTime);

digitalWrite(LEDpins[2],HIGH);
delay(vDelayTime);

digitalWrite(LEDpins[3],HIGH);
delay(vDelayTime);

digitalWrite(LEDpins[0],LOW);
delay(vDelayTime);

digitalWrite(LEDpins[1],LOW);
delay(vDelayTime);

digitalWrite(LEDpins[2],LOW);
delay(vDelayTime);

digitalWrite(LEDpins[3],LOW);
delay(vDelayTime);
}

////////////////////////////////////////////////////
// END MAIN PROGRAM
////////////////////////////////////////////////////

// Key entered by Anton da Bassguy 2011
// Tested March 04, 2011
//
// Complete success, plus I ran several other patterns
// by varying the pin numbers and their order.
//
// This is excellent material for studying how the
// Arduino uses arrays and subroutines!
///////////////////////////////////////////////////

Go BACK to Table of Contents
Cross reference
Schematic: C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\1003 Circuit Diagram Jpegs\Schematics
Breadboard: C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\1003 Circuit Diagram Jpegs\Breadboards
Sketch: C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\3002 Arduino Saved Sketches

013 ARDUINO MATH EXPERIMENT


013 ARDUINO MATH EXPERIMENT

March 8, 2011    (See also Companion Blog )
[Go BACK to Table of Contents] [ Next Experiment ] [ Last Experiment ]

           To program the Arduino to calculate the length of a hypotenuse, and to print it out to the serial monitor in plain English.

           There is no circuitry in this code. It is all code that is uploaded to the Ardunio for processing. But if everything goes right, the output should look like this:


Theory:
           The Arduino reads two input values, calculates a new value and prints all three values to the serial monitor. The progress of this experiment is the math, plus the fact the Arduino is generating a value that can be read on the remote computer. The computer is a component of this circuit, without it you could not view the results.

Practice:
           Qualified success. The Arduino can only handle integers in this experiment, so the values of Side A and Side B have to be chosen carefully to result in a whole number.

Conclusion:
           Math on the Arduino is as lame-brained and needlessly difficult as any other function in C code. The best thing to be said is that it works. The so-called “elegant” C language truncates any fractional parts without issuing any warning. The result is nonsense, like the following that shows the hypotenuse as 5 units, an obvious error.

           This experiment raises some questions. Can the results sent to the serial monitor be sent to other devices? The Arduino has no monitor, but I’ve seen it driving an LCD. Can the results of the math be stored on computer? On a flash drive? In an array? It seems to me a robot would behave better if it could rely on experience or “what worked right last time”, in combination with refined decision-making code. That sounds like a fancy way to say Artificial Intelligence.

Here is the code.

// Matches Experiment 013
// Today is March 08, 2011

/* This is a test of the math functions - a first here for me!
* It is copied from an Arduino Lesson 4 sheet found on-line
* "Arduino grows up and learns to talk".
* This experiment is how to do Arduino arithmetic.
*/

// INITIALIZATION
#include "math.h"
int a = 4;
int b = 4;
int h;
///////////////////////////////////////////////

///////////////////////////////////////////////
// MAIN PROGRAM
// Note: there is no void loop(), this code runs once and stops.
void setup()
{
Serial.begin(9600); // open serial port and send
// data to computer at 9600
Serial.println("Calculate a hypotenuese.");

Serial.print("a = ");
Serial.println(a);

Serial.print("b = ");
Serial.println(b);

h = sqrt(a*a + b*b);

Serial.print("h = ");
Serial.println(h);
}

void loop()
{
// runs continuously, but does nothing.
// note, the curly brackets are still required.
}
/////////////////////////////////////////////////////////////
// End Main Program
/* Created 2011-03-09
* Keyentered by Anton da Bassguy.
* First successful trial 2011-03-09
* Keep in mind, the material that displays on the computer
* is being sent from the Arduino chip, not computer memory.
* This is all new ground for me.
*/

Go BACK to Table of Contents
For Official Use Only
C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\2000 Minutes\Jpegs 2011-03 (Mar)
C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\2000 Minutes\Minutes 2011-00 (Intro)

014 BICYCLE BLINKER LIGHT ARRAY



014 BICYCLE BLINKER LIGHT ARRAY

March 9, 2011    (See also Companion Blog )

[Go BACK to Table of Contents] [ Next Experiment ] [ Last Experiment ]

           After the success of the blinking light system of Experiment 013, I had to forge ahead and create the blinking bicycle light. This was one of my milestones (it was supposed to take six months to get to this stage) and I was incredulous that it turned out to be relatively simple. A word of caution here, please remember that I am a seasoned programmer, and I’m programming light years ahead of my ability to design and produce the circuitry shown in examples like this, and infinitely ahead of my soldering skills.

           At the same time, the very nature of using a computer to control the workings of a mechanical device is precisely what I set out to do. In this case, it is blinking lights and it becomes difficult to imagine the thought that goes into the coding. Most people easily recognize that the same goals could be achieved electromechanically, but I am fascinated by the sheer control that digital processing can bring into play. This is the future, like it or not.


           Most of us have seen those bicycle lights that flash differing patterns depending on how many times you push a button. I have not button, but I can fake one with a strip of wire. Again, notice the simplicity of the wiring, all the hard work is done in the code.

           Naturally, in the future I hope to pair the two up in wizard proportions, you know, complicated circuits and complicated code. The casual reader should be reminded at this point I do not understand much of the theory and calculations in the physical circuit.

           Look at the schematic. In an ordinary configuration, depressing the switch would turn on all five LEDs. Notice the switch is momentary, which means it is pressed and then released. It does not stay on like a light switch, that is, it is only on momentarily on, then it disconnects for the next press. This is important and is known as a “normally open” switch. I hope to create a better way of displaying the Arduino pin configurations shortly.

Theory:
           When the switch is depressed, it causes a change in the system that depends on several factors, all inside the Arduino. The Arduino code is going to “count” the number of times the switch is depressed, changing the behavior of the 5 LEDs in four different patterns or “modes”. Therefore, the Arduino has to remember the last mode and replace it with the new mode. The only sophisticated component is this code, which always begins a cycle by turning all the LEDs off.

           The first press will turn the LEDs on, the second press makes them blink, the third press makes them chase around, and the fourth press turns them off to start a new cycle. Exactly like your bicycle light, except I built this one in an hour. The nearby photo, the fuzzy one, shows the wiring of my circuit.

Practice:
           It worked, but there were plenty of things to consider. You can examine the code included here to see that this is the most advanced program I’ve attempted so far. That was a lesson in itself. When the switch was pressed, the Arduino detected this external event and stepped the mode counter up one digit from 0 to 3, then back to 0. Even if you are a non-programmer, take a peek at my code below. Each digit caused a different pattern.

           I do not know why the resistor is in the switch leg, but several diagrams showed it, so I put it there. I used 1000Ω because it was handy. It would seem any time the switch went “high” by allowing 5V to flow through pin 2 would work here, but I found that the switch had to be positioned between the pin and the ground, not before pin 2. I have not thought that one through, maybe you can.

           One other new feature is the code shows that the status of the pin is read twice with a ten millisecond delay between the reads. There was a technical explanation in one of my sources that this is to prevent a “bounce”, which made sense, so there is the code snippet.

vPinStatus01 = digitalRead(SwitchPin); //store the SwitchPin value
delay(10); //bounce buffer
vPinStatus02 = digitalRead(SwitchPin); //store it again

Conclusion:
           This is the most robotic of any project for me to date. The actions of the LEDs were controlled by programming code that reads external conditions, in this case a switch press. I prefer the big picture: that I succeeded in getting one physical component to control a different physical component, and where there is smoke, there is confusion.

           The operation of the device involves illusion. At any given moment, only one LED is on. This winking effect is well known in ordinary light bulbs, which flash off and on 60 times per second. The Arduino is much faster and can control many more lights before the human eye could detect the flashing—although you can wave the Arduino back and forth rapidly and barely see a strobe effect.

           Allow me to emphasize the less obvious aspects. In a conventional design, the Arduino’s position in the design would be taken by banks of transistors, relays and timing capacitors. In this instance, there is no tangible connection between the switch (input) and the LEDs (output). Even less obvious is that, like a computer, the Arduino is fiercely churning away even when nothing is happening. A failure in the microchip means a failure in the whole system.

           The actual control of the system is tiny digital signals buried in the Arduino’s integrated circuit. I have no doubt there are transistors, relays and timing capacitors in there at a microscopic level, but these are not dedicated to the operation of this assembly of hardware. Without rearranging anything material, the hardware can be instructed to do something different.

           And that is the precise facet of robotics that I wish to learn, that I set out to learn. I may be wrong in my definitions, thanks to lack of any bona fide research material on the Internet. Until I stumble on something better, to me, the above interaction via the microcontroller IS my concept of robotics.

           The code is worth reviewing, although it suffers greatly in readability due to being C based.

// Experiment 014 - Blinking Bicycle Light
// Today is March 09, 2011
// This sketch corresponds to Minutes 014 blog

/* This is the bicycle light circuit.  It was inspired by
 * my $2 bicycle light, which flashes a pattern depending
 * on how many times you've pressed a button.
 * Note this button must be a momentary button, that is, once
 * you press it, it releases and does not stay pressed.
 * Based on Arduino Blinky Light Company.
 */
////////////////////////////////////////////////
//Begin Initialization & Variables
int SwitchPin = 2; //switch is connected to pin 2

int LED01pin = 12;
int LED02pin = 11;
int LED03pin = 10;
int LED04pin = 9;
int LED05pin = 8;

int vPinStatus01; //stores the pin 2 status after a read
int vPinStatus02; //bounce checker
int vButtonState; //stores the state of the button

int vLightMode = 0; //stores the on/off mode, initially 0
//End Initialization & Variables
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// Begin Main Program
/////////////////////////////////////////////////

void setup ()
{  //Begin setup
  pinMode(SwitchPin,INPUT); //set input to accept SwitchPin
  
  pinMode (LED01pin,OUTPUT);
  pinMode (LED02pin,OUTPUT);
  pinMode (LED03pin,OUTPUT);
  pinMode (LED04pin,OUTPUT);
  pinMode (LED05pin,OUTPUT);
  
  Serial.begin(9600); //Arduino communication speed
  vButtonState =  digitalRead(SwitchPin); //read initial state
} //End setup

void loop()
{ // Begin void loop
  vPinStatus01 = digitalRead(SwitchPin); //store the SwitchPin value
  delay(10); //bounce buffer
  vPinStatus02 = digitalRead(SwitchPin); //read the SwitchPin again
  
  if (vPinStatus01 == vPinStatus02) //pin status has not changed
  {  /////////////////////////////////////////////
    if (vPinStatus01 != vButtonState) //pin status has changed
    {  ///////////////////////////////////////////
      if (vPinStatus01 == LOW) //check if button pressed
      {  /////////////////////////////////////////
        if (vLightMode == 0) //if light is off
        {vLightMode = 1;                 //turn it on
           Serial.print("Mode is ");
           Serial.print(vLightMode);
           Serial.println(" On");}
//---------------------------------------------------------------------- 
          else
          {  
            if (vLightMode == 1) //if light is on //
            {vLightMode = 2;                   //make it blink //
             Serial.print("Mode is ");
             Serial.print(vLightMode);
             Serial.println(" Blinking");}
//-----------------------------------------------------------------------         
            else
            { 
              if (vLightMode == 2) //if light is blinking
              {vLightMode = 3;                 //make it wave //
               Serial.print("Mode is ");
               Serial.print(vLightMode);
               Serial.println(" Waving");}
 //-----------------------------------------------------------------------
              else
              {
                if (vLightMode == 3) //if on, blinking, waving
                {vLightMode = 0;               //turn it off //
                 Serial.print("Mode is ");
                 Serial.print(vLightMode);
                 Serial.println(" Off");}
              }  
//------------------------------------------------------------------------
            } //////////////////////////////////
          } //////////////////////////////////
      } ////////////////////////////////////
    }  ///////////////////////////////////
    
vButtonState = vPinStatus01;  //saves state of button
  }  
  
//This is the light blinking code
  if (vLightMode == 0) // if mode is 0, turn all off
  {
    digitalWrite(LED01pin, LOW);
    digitalWrite(LED02pin, LOW);
    digitalWrite(LED03pin, LOW);
    digitalWrite(LED04pin, LOW);
    digitalWrite(LED05pin, LOW);
  }
  if (vLightMode == 1) // turn all on
  {
    digitalWrite(LED01pin, HIGH);
    digitalWrite(LED02pin, HIGH);
    digitalWrite(LED03pin, HIGH);
    digitalWrite(LED04pin, HIGH);
    digitalWrite(LED05pin, HIGH);
  }
  if (vLightMode == 2) // blink mode
  {
    digitalWrite(LED01pin, HIGH);
    digitalWrite(LED02pin, HIGH);
    digitalWrite(LED03pin, HIGH);
    digitalWrite(LED04pin, HIGH);
    digitalWrite(LED05pin, HIGH);
    delay(100);
    digitalWrite(LED01pin, LOW);
    digitalWrite(LED02pin, LOW);
    digitalWrite(LED03pin, LOW);
    digitalWrite(LED04pin, LOW);
    digitalWrite(LED05pin, LOW);
    delay(100);
  }
  if (vLightMode == 3) // wave mode
  {
    digitalWrite(LED05pin,LOW);
    digitalWrite(LED01pin,HIGH);
    delay(50);
    digitalWrite(LED01pin,LOW);
    digitalWrite(LED02pin,HIGH);
    delay(50);
    digitalWrite(LED02pin,LOW);
    digitalWrite(LED03pin,HIGH);
    delay(50);
    digitalWrite(LED03pin,LOW);
    digitalWrite(LED04pin,HIGH);
    delay(50);
    digitalWrite(LED04pin,LOW);
    digitalWrite(LED05pin,HIGH);
    delay(50);
    digitalWrite(LED05pin,LOW);
  }
}  // End void loop

////////////////////////////////////////////////////
// END MAIN PROGRAM
////////////////////////////////////////////////////

// Key entered by Anton da Bassguy 2011
// Verified March 09, 2011.
// Corresponds to meeting minutes project 014
// and schematic 014 - Blinking bicycle light.
////////////////////////////////////////////////////


Go BACK to Table of Contents
Official Use Only – I always wanted to have a section like that.
C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\2000 Minutes\Minutes 2011-03 (Mar)
C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\2000 Minutes\Jpegs 2011-03 (Mar)
C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\3002 Arduino Saved Sketches\A100414_14BicycleLite

015 DIGITAL SWITCH BEHAVIOR



015 DIGITAL SWITCH BEHAVIOR

March 13, 2011    (See also Companion Blog

[Go BACK to Table of Contents] [ Next Experiment ] [ Last Experiment ]

           To investigate the behavior of a switch in a digital circuit. A moment’s thought first about three types of switches. One type is a throw switch, where you turn it on and it stays flipped in the on position, like a light switch. A second type is a momentary switch, where you press and release it but the effect continues, such as a computer power button. We accomplished this in Experiment 014. A third type is where you have to press and hold the switch, like a buzzer button.

           It is the third case I’ll look at here. It seems to be the most useful type for much of what I plan to do, so time to make sure I thoroughly understand the operation. In a sense, this is a momentary switch, but continuous for as long as you hold it down.

           This experiment borrows heavily from two sources, MakerShed1 Arduino 101 Add A Button and the Arduino Blinky Light Company introduced in Experiment 014, both available free on-line if you look for them. (The MakerShed video actually describes a situation where 0 Volts goes to ground, which I do not yet understand.)



Theory:
           Since there are no relays or solenoids in this circuit, the idea is to have the computer interpret the external environment and control the operation according to that information. As usual, the trade off is that if the computer loses power, the entire assembly will not work. The advantage is that if we succeed, a single brand of switch can serve two different purposes.

           If you are not the sort to examine schematics very closely, this is one that is worth every brain cell you put into memorizing it. It seems simple, until you try to follow the electrical paths. Do not overlook this schematic or try to skip it, you’ll regret that later.

           First look at the 5V path from the Arduino. It flows to the NO (normally open) switch and cannot get any further unless the switch is pressed.. The LED controlled by pin 10 (digital output) and will only change if pin 10 is HIGH, or 5V. But pin 10 will only be HIGH if pin 2 (digital input) is HIGH.

           Notice, both these legs of the circuit run through a high resistance (100K). This threw me until I realized pin 2 must put out a tiny current into the circuit even when it is idle. This tiny current is limited by the large resistor, although some must trickle through to ground.

           When the switch is depressed, the 5V power sees two possible paths, one through the large value resistor, or it can “push” an easier path back to pin 2. It takes this path of least resistance, literally. Pin 2 now reads HIGH, causing pin 10 to also go HIGH.

           All the rest is programming. If the light is off, pressing the switch makes it go on until the switch is released. If it is already on, pressing the switch will make it go off. One switch, two different results without changing any physical components.

Practice:
           Nothing yet. The circuit just sits there doing nothing. I suspect my wiring.

Conclusions:
           At least I learned the concept of a larger current clobbering a smaller current. Or is it voltage? Either way, the resistor in the circuit is a very operative component, not just there to prevent LED burnout.

Here is the code:

// Experiment 015 - Digital Switch Behavior
// Today is March 13, 2011
// This sketch corresponds to Minutes 015 blog

/* This will investigate the operation of a digital
 * switch controlled by the Arduino.  The effect of 
 * pressing the switch is determined by the computer
 * code, not the physical properties of the switch.
 */
////////////////////////////////////////////////
//Begin Initialization & Variables

int InputPin = 2; //set the digital input to read pin 2
int OutputPin = 10; //set the digital output to pin 10
int vVal = 0; //storage location for reading pin 2
                       //value, initialized to zero

//End Initialization & Variables
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// Begin Main Program
/////////////////////////////////////////////////

void setup()
{
  pinMode(InputPin, INPUT);
  pinMode(OutputPin, OUTPUT);
}
//-----------------------------------------------------------------------

void loop()
{
  vVal = digitalRead(InputPin); //read the input pin
  if (vVal == LOW) //if it is low, change it so
  {digitalWrite(OutputPin,HIGH);} //by default, the pin is high
//-----------------------------------------------------------------------
    else
    {  
      digitalWrite(OutputPin,LOW); //when the switch is pressed,
    }                              //turn off the LED
//----------------------------------------------------------------------- 
} // End void loop

////////////////////////////////////////////////////
// END MAIN PROGRAM
////////////////////////////////////////////////////

////////////////////////////////////////////////////
// Key entered by Anton da Bassguy 2011
// Verified March 14, 2011.
// Corresponds to meeting minutes project 015
// and schematic 015 - Digital Switch Behavior
////////////////////////////////////////////////////




1. MakerShed, which normally gets good marks from me, in this instance receives a “u”, my lowest possible rating. The reason is that their video disables the operational controls on my generic playback app. Once started, the video cannot be forwarded, paused, rewound or stopped without using Task Manager to disable the application.

Go BACK to Table of Contents

016 SPIN MOTOR WITH TRANSITOR CONTROL


016 SPIN MOTOR WITH TRANSISTOR CONTROL

March 16, 2011    (See also Companion Blog )
[Go BACK to Table of Contents] [ Next Experiment ] [ Last Experiment ]

           To control the speed and operation of a toy motor using a transistor responding to Arduino code.

           This is the first time I’ve used a diode and a transistor in a circuit, so I copied a trusted source: Arduino Experimenter’s Guide CIRC-003. From what I’ve read, the Arduino will supply a tiny voltage to the transistor base, thus causing a larger current to flow through the transistor and control the operation of the motor.

           I scrounged a small motor from a battery powered cassette player. The schematic shows the simplicity of the circuit, but take it from me, it is best to put in the effort to understand this experiment totally. Don’t get lazy here, you will regret it.

           I chose a general purpose transistor that came in a package of assorted numbers. It said they were good for general switching and amplification. Since I find the computer code easy to comprehend, I see that the code (shown below) will test both operations. Pin 9 can emit both a digital signal and a PWM signal which imitates an analog signal.

Theory:
           See the resistor between pin 9 and the transistor base pin? My guess is that it is there to limit the current, the Arduino puts out much more voltage than is needed to operate this transistor. See also the diode? I suspect it is there to prevent the motor from kicking backwards when it stops abruptly.

The microprocessor is programmed in three modes.
           Mode 1. Send a HIGH (5Volt) signal or a LOW (0Volt) signal. This should turn the motor on and off. The resistor is needed t limit the voltage or current from the Arduino, my guess is because 5Volts is just too much.
           Mode 2. Send an analog (PWM) signal telling the Arduino to spin fast for 2500 milliseconds, then spin slow for 1000 milliseconds.
           Mode 3. Send an analog signal telling the Arduino so gradually speed up and slow down.

Practice:
           The circuit worked perfectly in all three modes.

           Mode 1. The most precise is the digital on/off mode where the motor really kicks in on queue. It does not stop instantly because momentum causes it to wind down to a stop. I had to increase the delay speed to ensure it really was stopping. The motor almost instantly went to full speed when electricity flowed.

           Mode 2. The motor responded to quite rapidly to interim speeds. Where the digital was on or off, the analog PWM could select different speeds. I tested various combinations of fast and slow. All performed exactly as predicted. With analog, the motor seemed to take slightly more time to speed up and slow down.

           Mode 3: The code uses a digital counter to vary the motor speed from nothing to maximum. It faithfully did that for loop after loop. The acceleration was completely smooth, in fact smoother than most human operators could control the process.

           I placed a 100KΩ resistor across the base to see how tiny a signal the base would respond to. That resistor was too much, it effectively blocked the current to the transistor base and the circuit remained off. Next, I tried a 4700Ω resistor and it worked okay, but the motor cut off sooner during the loop. My speculation is that resistor caused the transistor to reach its lower threshold sooner.

Conclusion:
           The Arduino allows for precise control of a motor, but it is not as efficient as expected. In analog mode, there is a slight sluggishness to the response. Nobody else knew the purpose of the diode either. I would like to try other devices than a motor and sensor control in place of programming code.

           I added an LED and resistor in parallel to the supply side of the circuit. It perfectly reflected the changing current through the motor in all three situations. The LED responded much better than the motor, which makes sense because the motor is mechanical.

           Here is the code. Remember, there are three modes and you operate than by commenting out any two of the three subroutine calls in the void loop().

// Experiment 016 - Transistor Controlled Motor
// Today is March 15, 2011
// This sketch corresponds to Minutes 016 blog

/* Borrowed from "Interesting Easy Circuits",
* the Arduino Experimenter's Guide CIRC-003.
* This is my first circuit contained a transistor.
* Code is keyed in, not copied from the Internet.
*/
////////////////////////////////////////////////
//Begin Initialization & Variables

int BasePin = 9; //The transistor base lead
int vOnTime = 2500; //Motor on time in milliseconds
int vOffTime = 2000; //Motor off time in milliseconds

int vOnSpeed = 220; //Motor speed (0 - 255)
int vOffSpeed = 55; //Motor speed (0 - 255)


//End Initialization & Variables
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// Begin Main Program
/////////////////////////////////////////////////

void setup()
{
pinMode(BasePin, OUTPUT);
}
//-----------------------------------------------------------------------
//Read Instructions: this program calls three different subroutines
//from the void loop(). Notice that they are selected by commenting
//out any two, leaving the third subroutine to execute.
void loop()
{
//subMotorOnOff(); //calls subroutine “MotorOnOff”
//subMotorOnOffSpeed(); //calls subroutine “MotorOnOffSpeed”
subMotorAccelerate(); //calls subroutine “MotorAccelerate”
}
//-----------------------------------------------------------------------
void subMotorOnOff()
{
digitalWrite(BasePin, HIGH); //pulls 5V to base pin
delay(vOnTime);
digitalWrite(BasePin, LOW); //pulls 0V to base pin
delay(vOffTime);
}
//-----------------------------------------------------------------------
void subMotorOnOffSpeed()
{
analogWrite(BasePin, vOnSpeed); //variable voltage to BasePin
delay(vOnTime);
analogWrite(BasePin, vOffSpeed); //variable voltage to BasePin
delay(vOffTime);
}
//-----------------------------------------------------------------------
void subMotorAccelerate()
{ //Begin subMotorAccelerate()
for (int i = 0; i <= 255; i = i + 1)
{
analogWrite(BasePin, i);
delay(50);
}
//--------------------------------------------------------------------
for (int i = 255; i >= 0; i = i - 1)
{
analogWrite(BasePin, i);
delay(50);
}
} //End subMotorAccelerate()
//--------------------------------------------------------------------

////////////////////////////////////////////////////
// END MAIN PROGRAM
////////////////////////////////////////////////////

// Key entered by Anton da Bassguy 2011
// Verified March 15, 2011.
// Corresponds to meeting minutes project 016
// and Schematic 016 - Spin Motor
////////////////////////////////////////////////////

Go BACK to Table of Contents
Diagrams: C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\2000 Minutes\Jpegs 2011\Experiment 016
Code: C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\3002 Arduino Saved Sketches\A100414_016SpinMotor

017 MOTOR WITH PHOTORESISTOR CONTROL


017 MOTOR WITH PHOTORESISTOR CONTROL


March 21, 2011    (See also Companion Blog )

[Go BACK to Table of Contents] [ Next Experiment ] [ Last Experiment ]
           To have a photoresistor control a transistor, which in turn controls motor speed. Instead of hard code in the microprocessor controlling the motor, the idea is to read the value of a photoresistor. The photoresistor will change in resistance according to how much light is present. The brighter the light, the faster the motor speed, and if successful I will reverse the relationship to make the motor go slower.

           This is the first circuit I’ve tried that may have a practical value I can use. I would like a fan that runs faster as the day gets brighter and presumably hotter, a good idea in Florida. I know there is probably a less complicated schematic to depict my arrangement, but this is the version I understand. I’ve learned through study the motor diode, a 1N4001, is called a flyback control. Components which have a coil, such as a motor, will try to discharge that coil as the magnetic field collapses when power is removed, causing a spike of reverse current. The diode blocks that flow. Here is the breadboard schematic:



Theory:
           The photoresistor draws DC power from the 5V source, but limits this current by the amount of resistance caused by the prevailing light. Pin A0 sees this value which can range from 0 to 1023. It converts this to a transistor value 0 to 255 and sends this PWM signal to the transistor. This PWM value is output by pin D02 (digital pin 2) to the transistor base pin. The transistor reacts by controlling the current through the motor, hence the motor speed.

Practice:
           I’m getting some partially successful results. It took a bit for me to clue in that to make a digital pin use PWM, you have to write to it with the analogWrite command. Nobody took the time to make that clear, but I know it now. The photoresistor acts like an independent part of the circuit, don’t get thrown by how it uses common power and ground connections.
           The PWM signal was not getting through the standard 1000Ω resistor, so I took it down to 330Ω. The motor reacts instantly, but with strange behavior. Where I was expecting a smooth acceleration, the motor slows down when the light is blocked, but when the light returns, the motor does not run smoothly at all. It kicks and sputters. The good news is it does so in direct response to the photoresistor.


Conclusion:
           I determine the erratic motor response to be some wiring or component error that does not affect the validity of this experiment. The circuit includes a NPN transistor as a control and I’m not that familiar with transistors yet. Even without refining the motor operation, this experiment is a success, and the most complicated analog circuitry I’ve ever built myself.
Here is the code:

// Experiment 017 - Photosensor Transistor Controlled Motor
// Today is March 17, 2011
// This sketch corresponds to Minutes 017 blog

/* Adapted from several sources detailing the motor
* and sensor parts of this circuit, brough together here.
* Code format is my original work. The plan is to read
* a photosensor, send this data back to the Microprocessor
* and have it control the speed of a small motor. As
* the light gets brighter, the motor speeds up.
*/

////////////////////////////////////////////////
//Begin Initialization & Variables

int PhotoResistor = 0; //The photocell pin (Input)
int vPhotoResistorValue; //Storage for photocell value
int MotorPin = 3; //The Motor control pin (Output)
int vPWM = 0; //Convert 10 bit to 8 bit

//End Initialization & Variables
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// Begin Main Program
/////////////////////////////////////////////////

void setup()
{
analogReference(DEFAULT);
pinMode(MotorPin, OUTPUT); //Arduino controls pin 2
Serial.begin(9600); //Enable serial monitor read
}
//-----------------------------------------------------------------------
void loop()
{
vPhotoResistorValue = analogRead(PhotoResistor); //Read the photocell
Serial.println(vPhotoResistorValue); //Display the value on serial monitor
vPWM = map(vPhotoResistorValue, 530, 680, 0, 255);
analogWrite(MotorPin, vPWM); //Ouput PWM value to motor control
delay(500); //Slow things down
}
//-----------------------------------------------------------------------

////////////////////////////////////////////////////
// END MAIN PROGRAM
////////////////////////////////////////////////////

018 HOME MADE LED DOT MATRIX DISPLAY - 3x3 MATRIX



018 HOME MADE LED DOT MATRIX 3x3

March 16, 2011    (See also Companion Blog )

[Go BACK to Table of Contents] [ Next Experiment ] [ Last Experiment ]

           To build and program a 3 x 3 LED dot matrix display using only LEDs, resistors and the Arduino brainboard. This project is completely original and is not based on any kit or plans that I could find, in fact, I had to build it because I could not find any proper instructions or tutorial material.

           Be advised: this is a complicated project that took a lot of time. You should read through this description before you start to see what to expect and learn what you are in for. This project requires both complicated wiring and complicated Arduino code, at least if you ask me.

           You will need to plan out your tools and materials. I can’t do that for you, but you also will need the basics and some way to connect all the wiring. This project took me five hours to complete, around four hours for the wiring, and another hour for the programming. But keep in mind I have a degree in programming and was able to plan the code in my head.

           I apologize now and probably again later that I do not have the cash or equipment to take acceptable photos of what I’m doing. I’ve tried to record the events using what I’ve got and I am aware of the shortcomings. However, this is an experiment, not something for sale. Follow along and give it a try if you feel motivated.

           There is nothing difficult about the individual steps and components that make up such a circuit. But what is difficult is finding a source that explains everything in a simple fashion. I wasted much time watching on-line videos that didn’t show the code, or didn’t reveal the wiring schematics. Guys, you may be proud of your project, but without the technical details, your video is just some flashing lights and boring commentary.
Theory:
           Let’s get some terminology out of the way. The correct name for the apparatus is “LED Dot Matrix”. I spent considerable time on Google trying to find a beginner’s level document and got led down many a wrong path. Some people referred to the object as an array, but an array is a mathematical concept, part of the Arduino code you may eventually use. I don’t use it here.

           Other authors called it an LED flashing sign, but these were the usual gangs of commercial outfits looking to sell you the finished product. You don’t learn much buying a kit, either. It is too bad Google has no way of blocking these bait and switch operators. There are also slang terms like LED grid, but from here on, when I say the matrix, I mean the LED Dot Matrix display.

           Do not confuse an LED dot matrix display with and LCD (liquid crystal display). These are two different animals. The LCD is a manufactured component you cannot build at home, and it is controlled with a matching IC (integrated circuit), a chip that is much more advanced than what we are doing here.

           Before you begin, there are many things to know that are not covered elsewhere, so I take the liberty of bringing them together here. The smallest practical LED Dot Matrix is a 3 x 3, anything smaller won’t give you the feel for the correct wiring—and you WILL need that knowledge learned here when you scale up to larger matrices (the correct plural of matrix) later.

           Words to the wise. Be advised there is no way an ordinary breadboard with banks of 5 parallel slots can be used to produce a 3 x 3 matrix, it is physically impossible. Don’t waste your time trying like I did.

           The term dot matrix has been around, some of us are old enough to remember dot matrix printers. You should make an attempt to understand the theories behind dot matrix printing, and how the minimum number of dots needed to display all the alphanumeric characters was derived. For practical purposes, most matrix displays are 8 x 8, which allows some “space” around each displayed character. It is worthwhile to read up a few paragraphs on dot matrix before you commence building anything here.
           Here are some patterns I made around six months ago, long before I had contemplated actually building a matrix. I found limitations of what could be displayed on 3 x 5 matrix and gives you some direction about how to think concerning how to present characters in dot matrix format.

           Next, try to use red or yellow LEDs, the 5mm brand. They have the brightness required to be seen in ambient room light and you don’t want to be continually turning off the overhead to see if you are making progress. Also, these colors tend to switch on and off instantly where other colors seem to have a noticeable delay time turning off, although I have not measured or confirmed this delay.

           The Arduino will supply barely enough power to experiment with small LED matrices. Beyond that, you will have to use transistors. If you are not familiar with transistors, they serve a dual function in a matrix circuit: they act as switches and they act as amplifiers. The amplifier part allows you to connect a power supply independent of the Arduino. I recommend that you plan to use transistors as early in your matrix projects as you can.

           When you see a pattern displayed on a dot matrix, what you are really seeing is all of the LEDs flashing on and off so rapidly that your POV (persistence of vision, about 1/20th of a second) makes your eye perceive that they are all on at once. Sometimes this flashing is controlled by multiplexing, but this is not what I used here. The concept of multiplexing comes into play when you have more LEDS to control that the Arduino has outputs. This project is planned to use only six of the available pins on the Arduino.

           For clarity, only one LED is on at a time. The computer code flashes each LED in sequence. Your eye and brain perceive the character or pattern, but this is an illusion. The one-at-a-time flashing has a theoretical upper limit in that more LEDS mean more of a delay before each one gets its turn. But the Arduino can flash so many thousands of times per second it is not likely you will ever reach this limit or even notice that more LEDs are slightly dimmer than a few LEDs.

           In an LED matrix, all your positive (anode) LED pins are connected in each row, your negative (cathode) LED pins are connected by columns. Thus, to turn on an individual LED, you will need to set the corresponding positive to HIGH (5Volts) and the corresponding negative to LOW (0 Volts). To turn the LED off, remove the HIGH and LOW.            This may seem obvious, but it is not. Think for a moment about the situations where the LED would be off. It the negative lead was also set to HIGH, no current would flow. But there is potential for damage to your LED in such a configuration. Later, you will see how using transistors as switches helps in this situation.

           No matter how you approach the wiring, it is a tiresome task that demands full concentration. The connections are tiny and look alike for the most part. The real lesson you learn is that matrices are best constructed by automated means. You will probably never build a matrix beyond what you require to learn how it is done. Practice:

           My layout was wire-wrapped. I avoided soldering because I am not that good at it, while I am very experienced with wire wraps. In the event of an error, I find a wire wrap easier to undo than a solder joint. Also, I’m cheap when it comes to wiring a circuit I intend to tear apart if it works. Whichever you choose, your patience will be tried to the ultimate.
           Here’s another factoid difficult to discover from the Arduino manual—all the pins default to INPUT. You can see in the code how I specifically instruct the pins to be set to OUTPUT. If you don’t spell it out, the Arduino isn’t going to help. This is not a trivial step, and the default setting can be totally confusing to newcomers.

           I had to start somewhere, so here is my first attempt. I used yellow LEDs because I have lots of cheap ones not destined for any other usage. I have a store-bought perfboard and I will not be using any transistors on this grid. I only want to test the logic of turning on the LED targeted by my Arduino code.

           As a precaution against short circuits, I staggered the rows and columns of my LED leads on the perfboard. That is, I did not line the leads up in the same colums. I placed them diagonally. See nearby diagram. This made the leads easier to distinguish and work with.
           I wired my matrix on a perfboard, with a layer of stiff paper between the anode and cathode leads to prevent any short circuits. The mass of wires and leads are too close for my soldering skills at this time. The wire wraps have no structural strength so the paper was necessary for me to complete the matrix in reasonable time. I got the idea for the paper after watching a youTube video on layered printed circuit boards. My wire was 30 AWG jumper wire from the Shack, where I also purchased a wrapping tool. It takes about 5 minutes to learn to wrap like a pro, I can’t say that about soldering.

           The paper was cut in strips, first one direction, shown partially completed here, then the perpendicular direction as this gave the solderless joints more stability. I’ll let you figure out how I used an old sponge and a paperclip to line the holes up exactly. For some reason, component leads do not exactly match the drill holes on either breadboards or perfboards.


           Since the so-called authorities on this subject don’t mention it, be sure to use insulated wires for your matrix connections. I saw several jpegs where bare wire was used and it just doesn’t make sense to take that kind of chance because shorts on a matrix are very hard to detect. Take an extra look at my progress photos, for if this type of intricate wiring isn’t your strong point, now is the time to have second thoughts about this project. You can buy ready made matrix components.

           You may be able to spot where I ran out of 1,000 Ω resistors and used some 330 Ω in series. Several sources said to use 1,000 Ω resistors in all LED matrix circuits, although all of them failed to give a good reason why that is so. I’m merely following orders on this one.

           At this point, you have built the matrix, complete with resistors. I could not find a good schematic or description, so I took a large and complicated schematic of a multicolor matrix, zoomed in and very slowly erased all the parts I did not need. The result is the 9 LED diagram shown nearby. The wires that cross are not nodes, they are not connections.
           Before you do any Arduino work, you may want to take a battery supply and test the circuit for shorts and other problems. You can see me testing the middle LED. I spent twenty minutes looking for a short in the LEDs for what turned out to be a short on one of the resistors. Beyond that, this 3 x 3 matrix tested fine the first time. Here is a diagram of my logic. In the end, it was so tricky to keep track of the rows and columns that I named the columns X, Y, and Z.
           Let me say that most of the videos and on-line material is not helpful in this department. The ones that show the matrix don’t show the matching code and vice versa. Some code included libraries I could not find. So I set down to programming the LEDs one by one using a loop. My goal is to have the LEDs light up alternatively in an “x” and then a “+” with a pause between the patterns.

           Another important point not adequately explained in the material I read is the exact logic of how to turn on the correct LED. It is not enough to simply rely on your prior knowledge that a current will flow from source to ground, since you have more than one LED in series on each row or column. Try to follow my logic on how I solved this issue below.

           When you connect the cathodes to ground, they will always be grounded. Thus, any voltage to an LED will light up that entire row, not just the single LED. Thus, I have to leave the voltage HIGH for the cathodes connected to the LEDS I want turned off. No voltage will flow from HIGH to HIGH. This seems to fly against logic--that I have to turn a pin on HIGH to get an LED to remain unlit. You will run up against this quirk many times when working with a matrix.

           All the pins are output. All are controlled by commands from the Arduino, there is no interface with the outside in this circuit. Applying Boolean AND logic, a given LED should light only when its anode (positive) pin is HIGH and its cathode (negative) pin is LOW. There may be other ways to approach this situation, but if so, whoever knows them is keeping it a big secret. The LOW state must be as carefully controlled as the HIGH state.

           I arbitrarily chose pins 3, 5, and 6 for the anode pins, and 9, 10, and 11 for the cathodes because they are the PWM-enabled pins farthest apart on the brainboard, making my wiring just a little easier. Follow the code very carefully when you decide to read it, there are many pitfalls. (Question: why do I have to declare a pin as an integer? There is no pin 3.7 or 9.4, right?)

           Later, I figured out I did not need any pins with PWM for the working of this circuit, but it’s not like anybody was kind enough to say so before I got started. Maybe they were born knowing all the tiny details and don’t see any need to explain anything to their audience. Fact is, any set of pins will work, since they will exist only in HIGH and LOW state for the purposes of this experiment, no PWM needed. Ah, but what if I want to dim the LED instead of turning it off? Sure, if I live long enough. Let’s keep focused with simple ON and OFF.

           In the first pass through the code, I programmed the two patterns in one long chunk, thinking the void loop would keep calling them and causing things to look right. Nope, and although that loop could probably be made to work, it would be cumbersome. Although I’ve got the patterns to display, they ripple through each pattern so fast it can barely be seen until the last LED (in the code sequence). Again, it could be made to work, but at the expense of complicated and inflexible code.

           So, back to the drawing board. When I ran the code, all nine LEDS lit up. Something else must control the LEDs that I missed. The LEDS were flashing in sequence too fast for my slow eye. Let me slow things down (note the delay command strategically place to do just that). Wait, I got something to work on the second pass. Okay partial success. I can get the lights to flash in sequence, first the “x” pattern, then the “y” pattern by placing a 200 millisecond delay between each flash so I can see the results. And you were wondering why I had that delay command repeated so many times in the code . . . .

           But when I speed it up to see the POV effect, it does not happen. But the concept is good enough in that I have found a way to control specific LEDs that I figured out on my own, pat on the back here. Yet something is still wrong but nobody is going to quit now. The circuit loops once, very rapidly, then stalls. There is a logic error and those can be nasty. The tendency of programmers with a C+ mindset would be to keep adding more code until it worked.

           When I suspect my logic, I don’t blame my code. I think I need to code the patterns in subroutines, and call the subroutines in rapid sequence. This would also make the code more adaptable. That didn’t work either, since each subroutine ran once really fast, again moving rapidly to the last LED called, then leaving that LED lit until the next subroutine was called. It isn’t working.

           Thinking it through, I’m going to introduce a “for” loop in the code, first in the void loop, and if that doesn’t work, then in the subroutines. The idea is to have the code call the subroutine repeatedly for long enough to see the patterns. This is a crude brute force approach made necessary by primitive programming languages like C+. Examine the void loop code.

           Ha, note the syntax “examine the void loop”, only a C+ programmer would see nothing wrong with that sentence. They call it C+ programming because that is the average mark of the people who use it. All the C+ programmers are busy from last week’s change to daylight savings. They are still pouring sand out of their sundials.

           Son-of-a-gun, it works! I don’t have the photography equipment to get you working videos and clear photos of what I’m doing, but if you follow the code, I believe you may be able to see how I got this to work “on the fly”. There are probably far better or more efficient ways to accomplish the same thing, but this is the version I understand. For now. I took out the center LED in the cross pattern because it looked like it was on all the time. So instead of a cross, I have a diamond pattern.
           Without saying this is the right way to do things, I can say it worked for me. If you can do what I just did, the next step is to move to transistors to do the switching. They are supposed to be better at controlling a matrix, but danged if I can find anybody on line who will tell me why in plain terms. Warning, a project like this can cause you to have to re-wire your brain along. It is unlike anything in real life. I’ve never done anything like this before.

           I’ve attempted to upload a video of the successful operation here. Blogspot claims that their system is compatible with AVI, but despite following the directions to the letter, I cannot get a video to embed. Any assistance would be helpful.
Conclusion:
Two new things I learned from this experiment are:
           1. Now I know why so many people drop out of engineering school.
           2. Now I know why those who make it seem to lose their ability to relate to regular humans in terms everybody can understand.

           With this experiment, I’ve outdone myself and gone past my ability to work with other components. I can’t even solder worth a darn yet. I have a head start with matrix algebra and the brand of thinking needed to visualize the code so do not dismay if you don’t get it so easily. The remainder I am learning from scratch. But I’ve gone beyond my own aptitude with this crazy experiment which I did on a whim. I got lucky this time.

           In real life, this matrix would not be very rugged. For example, I used the fact that the LEDs only conduct in one direction. If an overvoltage hit the circuit beyond the threshold of the LED, it would probably be destroyed. I had also read in advance that the Arduino could power LEDs, but that larger loads require an independent supply.

           Here is the code. I’m the first to admit it is lengthy and repetitious. But if I cleaned it up and used arrays for the patterns, it would be harder to understand. (I intend to build a bigger matrix with discount LEDs from Hacktronics at which time I will attempt to streamline the code.) It would be nice if my critics allow that this is the first time I have ever done anything like this am just a few months into this hobby. Here it is, warts and all:

/* This is an LED dot matrix experiment
* It matches Experiment 018 in the Minutes
* Please refer to the notes to construct the matrix needed for
* this code. Your LEDs must be perfect and tested before
* proceeding with the code, as the matrix is hard wired.
* Today is March 22, 2011
*/

////////////////////////////////////////////////////////////////////////////
//Begin Initialization & Variables

int PinColX = 11; //Assigns the pins for the
int PinColY = 10; //columns. I used letters to
int PinColZ = 9; //minimize confusion.

int PinRow01 = 3; //Assigns the pins for the rows
int PinRow02 = 5; //I arbitrarily started counting
int PinRow03 = 6; //from the top left and across.

int vDelay = 1; //used only for debugging, set to 1 otherwise
int vTimer = 50; //sets the speed for the display loop


//End Initialization & Variables
////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
// Begin Main Program
////////////////////////////////////////////////////////////////////////////

void setup()
{
pinMode(PinColX, OUTPUT); //all pins used in this sketch are outputs
pinMode(PinColY, OUTPUT);
pinMode(PinColZ, OUTPUT);

pinMode(PinRow01, OUTPUT);
pinMode(PinRow02, OUTPUT);
pinMode(PinRow03, OUTPUT);

}
//-----------------------------------------------------------------------
void loop()
//this loop calls the subroutines repeatedly to keep the LEDS lit.
//make sure you follow this logic completely before continuing.
{
for (int i = 0; i <= vTimer; i = i + 1)
{
subPatternEX(); //calls the pattern that displays an "x"
}
//-----------------------------------------------------------------------
for (int i = 0; i <= vTimer; i = i + 1)
{
subPatternCR(); //calls the pattern that displays a "diamond"
}
}
//----------------------------------------------------------------------
void subPatternEX() //this is the pattern that displays an "x"
{
digitalWrite(PinColX, HIGH); // X O O Sets column 1 high
digitalWrite(PinColY, LOW); // X 0 0
digitalWrite(PinColZ, LOW); // X 0 0

digitalWrite(PinRow01, LOW); // 0 0 0 Sets row 1 low
digitalWrite(PinRow02, HIGH); // X X X
digitalWrite(PinRow03, HIGH); // X X X
delay(vDelay); //debugging delay
//----------------------------------------------------------------------
digitalWrite(PinColX, LOW);
digitalWrite(PinColY, LOW);
digitalWrite(PinColZ, HIGH);

digitalWrite(PinRow01, LOW);
digitalWrite(PinRow02, HIGH);
digitalWrite(PinRow03, HIGH);
delay(vDelay);
//----------------------------------------------------------------------
digitalWrite(PinColX, LOW);
digitalWrite(PinColY, HIGH);
digitalWrite(PinColZ, LOW);

digitalWrite(PinRow01, HIGH);
digitalWrite(PinRow02, LOW);
digitalWrite(PinRow03, HIGH);
delay(vDelay);
//----------------------------------------------------------------------
digitalWrite(PinColX, HIGH);
digitalWrite(PinColY, LOW);
digitalWrite(PinColZ, LOW);

digitalWrite(PinRow01, HIGH);
digitalWrite(PinRow02, HIGH);
digitalWrite(PinRow03, LOW);
delay(vDelay);
//----------------------------------------------------------------------
digitalWrite(PinColX, LOW);
digitalWrite(PinColY, LOW);
digitalWrite(PinColZ, HIGH);

digitalWrite(PinRow01, HIGH);
digitalWrite(PinRow02, HIGH);
digitalWrite(PinRow03, LOW);
delay(vDelay);
//----------------------------------------------------------------------
}

void subPatternCR() //this is the pattern that displays the diamond pattern
{
digitalWrite(PinColX, LOW);
digitalWrite(PinColY, HIGH);
digitalWrite(PinColZ, LOW);

digitalWrite(PinRow01, LOW);
digitalWrite(PinRow02, HIGH);
digitalWrite(PinRow03, HIGH);
delay(vDelay);
//-----------------------------------------------------------------------
digitalWrite(PinColX, HIGH);
digitalWrite(PinColY, LOW);
digitalWrite(PinColZ, LOW);

digitalWrite(PinRow01, HIGH);
digitalWrite(PinRow02, LOW);
digitalWrite(PinRow03, HIGH);
delay(vDelay);
//-----------------------------------------------------------------------
digitalWrite(PinColX, LOW);
digitalWrite(PinColY, LOW);
digitalWrite(PinColZ, HIGH);

digitalWrite(PinRow01, HIGH);
digitalWrite(PinRow02, LOW);
digitalWrite(PinRow03, HIGH);
delay(vDelay);
//-----------------------------------------------------------------------
digitalWrite(PinColX, LOW);
digitalWrite(PinColY, HIGH);
digitalWrite(PinColZ, LOW);

digitalWrite(PinRow01, HIGH);
digitalWrite(PinRow02, HIGH);
digitalWrite(PinRow03, LOW);
delay(vDelay);
}
//-----------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////
// END MAIN PROGRAM
////////////////////////////////////////////////////////////////////////////

// Key entered by Anton da Bassguy 2011
// Tested and compiled 2011-03-22
// There is no easy way to describe the logic of the digitalWrite statements
// above, it is best to just step through the code until it makes sense.
// Tested again 2011-03-23

////////////////////////////////////////////////////////////////////////////