Lighting random LEDs in 8x8 pattern

Hi all.

I am quite new to this, and am not sure where I am going wrong.

I'm trying to make one led light up at random from an 8X8 array (I think the code seems quite self explanatory).

Any help with this would be greatly appreciated... (but let me know if I am off on a tangent and I will have to abandon the project... which would be a pity... as I did spend a few hours soldering everything in place.. :slight_smile:

//This program uses 8x8 LED matrix and randomiser for central commander console
//written for the starblaster cockpit

/*
  Star Blaster Cockpit Radar
  see book for wiring diagrams

Random LED flasher by Brett
Circuit = 8x8 LED's (8 rows, 8 colums)
100 ohm resistors on cathodes

cathodes to pins 0,1,2,3,4,5,6,7
anodes to pins 8,9,10,11,12,13,A1,A2
//
*/

int rowranNum;        //row pin No.
int colranNum;         //colum pin No.
int pause;                //delay time


void setup() {

  // Setup cathodes (row No.s)

  pinMode(0, INPUT);
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(7, INPUT);

// Setup anodes (colum No.s)
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(16, OUTPUT);


}


void loop() {

  //Generate random number
  rowranNum = random(0, 7);
  colranNum = random(8, 16);

  // Generate random delay time
  pause = random(25, 500);


  //Turn on the LED
  digitalWrite(colranNum, HIGH);
  digitalWrite(rowranNum, LOW);

  delay(pause);

  //Turn off the LED
  digitalWrite(colranNum, LOW);
  digitalWrite(rowranNum, HIGH);

}

Personally I would avoid using pins 0 and 1 as they are used by the Serial interface.

  pinMode(13, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(16, OUTPUT);

Did pin 14 go missing ? The random selection includes 14

The built in LED on pin 13 may affect the output to another LED connected to it

UKHeliBob:
Personally I would avoid using pins 0 and 1 as they are used by the Serial interface.

  pinMode(13, OUTPUT);

pinMode(15, OUTPUT);
  pinMode(16, OUTPUT);



Did pin 14 go missing ? The random selection includes 14

The built in LED on pin 13 may affect the output to another LED connected to it

I missed pin 14 (A0) when soldering..
(not sure how to adjust the code to reflect that)

(not sure how to adjust the code to reflect that)

Put the pin numbers in an array then choose a random number between 0 and 7 to select the pin number. That way the pin numbers do not have to be contiguous

Just for my education...why are the row pin modes set as INPUT? It seems a bit odd. Doesn't that put them in high impedance mode and then writing to them just switches the internal pull up resistors in and out?

Steve

slipstick:
Just for my education...why are the row pin modes set as INPUT? It seems a bit odd. Doesn't that put them in high impedance mode and then writing to them just switches the internal pull up resistors in and out?

Steve

you are right.. that is not necessary. but even with that removed from the code, it still does not work...

BillDitt:
you are right.. that is not necessary. but even with that removed from the code, it still does not work...

Thanks Steve.. Got it now (changed the INPUT to HIGH)... Problem solved..

Yep, pins need setting to OUTPUT because they unhelpfully default to INPUT. I guess HIGH = OUTPUT (I learn something every day).

Steve