Arduino Application Development Procedure Part-3

In the second post in this series: Arduino Application Development Procedure Part-2 , I provided a bill of materials, breadboard diagram, and some wiring tips. In this brief post, I will provide my first step in programming: testing to make sure the wiring is correct. I would strongly advise starting by testing all the input and output on a larger project like this to avoid further debugging or troubleshooting by finding out input or output isn’t working. The program doesn’t have to be complicated, but I would suggest setting up initial variables that you think you will use so you can just add on to the code you already have. Here is what I had for this first step:

/*
 * This part of the design phase is important, I would recommend setting up a base program to test that you wired everything correctly. In this case, 
 * we have a lot of wires going different places, red wires for routing to resistors for red lights, yellow wires for routing to resistors for blue lights,
 * black wires for routing from the red light resistors to the IOs, white wires for routing from the blue light resistors to the IOs, and blue wires for
 * wiring all the pushbuttons to pull-down resistors and to their IOs. I will use this code in the final product except for the light sequence (that is just for testing the LEDs)
 */
//define red output pins
#define RR3C3 53
#define RR3C2 52
#define RR3C1 51
#define RR2C3 50
#define RR2C2 49
#define RR2C1 48
#define RR1C3 47
#define RR1C2 46
#define RR1C1 45
//define blue output pins
#define BR1C1 22
#define BR1C2 23
#define BR1C3 24
#define BR2C1 25
#define BR2C2 26
#define BR2C3 27
#define BR3C1 28
#define BR3C2 29
#define BR3C3 30
//define input pins
#define R3C1IN 34
#define R3C2IN 3
#define R3C3IN 4
#define R2C1IN 35
#define R2C2IN 6
#define R2C3IN 7
#define R1C1IN 8
#define R1C2IN 9
#define R1C3IN 10
void setup() {
  pinMode(RR1C1, OUTPUT);
  pinMode(RR1C2, OUTPUT);
  pinMode(RR1C3, OUTPUT);
  pinMode(RR2C1, OUTPUT);
  pinMode(RR2C2, OUTPUT);
  pinMode(RR2C3, OUTPUT);
  pinMode(RR3C1, OUTPUT);
  pinMode(RR3C2, OUTPUT);
  pinMode(RR3C3, OUTPUT);
  pinMode(BR1C1, OUTPUT);
  pinMode(BR1C2, OUTPUT);
  pinMode(BR1C3, OUTPUT);
  pinMode(BR2C1, OUTPUT);
  pinMode(BR2C2, OUTPUT);
  pinMode(BR2C3, OUTPUT);
  pinMode(BR3C1, OUTPUT);
  pinMode(BR3C2, OUTPUT);
  pinMode(BR3C3, OUTPUT);
  pinMode(R3C1IN, INPUT);
  pinMode(R3C2IN, INPUT);
  pinMode(R3C3IN, INPUT);
  pinMode(R2C1IN, INPUT);
  pinMode(R2C2IN, INPUT);
  pinMode(R2C3IN, INPUT);
  pinMode(R1C1IN, INPUT);
  pinMode(R1C2IN, INPUT);
  pinMode(R1C3IN, INPUT);
  //use serial for checking if buttons are wired correctly
  Serial.begin(9600);
}

void loop() {
  //loop the red lights by beginning with row 1 col 1 and ending on row 3 column 3
  int i = 45;
  //check buttons individually by each abbreviated variable for "location" in grid, tedious process but better than trying to distinguish what value is what and don't have to print extra text
  Serial.println(digitalRead(R3C3IN));
  for(i; i <= 53; i++){
    digitalWrite(i, HIGH);
    delay(100);
    digitalWrite(i, LOW);
  }
  //loop backwards direction with the blue lights this time
  int i2 = 30;
  for(i2; i2 >= 22; i2--){
    digitalWrite(i2, HIGH);
    delay(100);
    digitalWrite(i2, LOW);
  }
}

As explained in the code via comments, I decided to test each button individually by changing the digitalRead() function. This is more tedious, but I’d have to write more in this stage to “distinguish” different inputs. Also, the serial monitor still goes pretty fast and I’d rather not put in delay just to accomplish a simple test. I used shorthand names using #define for the different positions in the grid. RR1C1 stands for red row one column one, BR1C1 stands for blue row one column one, and R1C1IN stands for row one column one input, I needed a convenient and easy way to remember names for the final program. The values never change so the “#define” syntax in C works great for this program. The next post covers a much more difficult task: figuring out the sequencing for taking turns between players.