int cols[5] = {9, 10, 11, 12, 13}; //pins of the coloms int rows[5] = {4, 5, 6, 7, 8}; //pins of the rows void setup() { for (int i = 4; i < 14; i++) { //declare pins as outputs pinMode(i, OUTPUT); } for (int i = 0; i < 5; i++) { digitalWrite (cols[i], HIGH); //set all colom-pins to HIGH digitalWrite (rows[i], LOW); //set all row-pins to LOW } } void loop() { //random colom is selected byte randomCol = random(0,5); //setting this random col to LOW digitalWrite (cols[randomCol], LOW); for (int i = 0; i < 20; i++) { for (int y = 0; y < 5; y++) { //selcet the row and set it HIGH digitalWrite (rows[y], HIGH); delay(1); //reset of the selected row digitalWrite (rows[y], LOW); delay(1); } } //setting this random col to HIGH => reset the pin digitalWrite (cols[randomCol], HIGH); }