#define numberOfRows 3 #define numberOfColumns 3 #define numberOfLayers 3 #define numberOfAnodes numberOfRows*numberOfColumns #define nonUsedAnodes 7 #define nonUsedCathodes 5 int serialAn = 41; int rclkAn = 39; int srclkAn = 37; int srclrAn = 35; int serialAn1 = 33; int rclkAn1 = 31; int srclkAn1 = 29; int srclrAn1 = 27; int serialCat = 8; int rclkCat = 6; int srclkCat = 4; int srclrCat = 2; void setup(){ //anodes pinMode(serialAn, OUTPUT); pinMode(rclkAn, OUTPUT); pinMode(srclkAn, OUTPUT); pinMode(srclrAn, OUTPUT); pinMode(serialAn1, OUTPUT); pinMode(rclkAn1, OUTPUT); pinMode(srclkAn1, OUTPUT); pinMode(srclrAn1, OUTPUT); //cathodes pinMode(serialCat, OUTPUT); pinMode(rclkCat, OUTPUT); pinMode(srclkCat, OUTPUT); pinMode(srclrCat, OUTPUT); //clearing out the registers digitalWrite(srclkAn, LOW); digitalWrite(serialAn, LOW); digitalWrite(srclrAn, HIGH); digitalWrite(rclkAn, LOW); digitalWrite(srclrAn, LOW); digitalWrite(rclkAn, HIGH); digitalWrite(srclrAn, HIGH); digitalWrite(srclkAn1, LOW); digitalWrite(serialAn1, LOW); digitalWrite(srclrAn1, HIGH); digitalWrite(rclkAn1, LOW); digitalWrite(srclrAn1, LOW); digitalWrite(rclkAn1, HIGH); digitalWrite(srclrAn1, HIGH); digitalWrite(srclkCat, LOW); digitalWrite(serialCat, LOW); digitalWrite(srclrCat, HIGH); digitalWrite(rclkCat, LOW); digitalWrite(srclrCat, LOW); digitalWrite(rclkCat, HIGH); digitalWrite(srclrCat, HIGH); } void loop(){ for(int i=1; i<=numberOfColumns; i++){ for(int j=1; j<=numberOfRows; j++){ for(int k=1; k<=numberOfLayers; k++){ lightUpOneLed(j,i,k,100); } } } } int offLed; int onLed; void lightUpOneLed(int anodeRow, int anodeCol, int cathodeLayer, int lightDuration){ int anodeNumber= (anodeRow*3-3)+anodeCol; //turning on the specific anode digitalWrite(rclkAn1, LOW); digitalWrite(rclkAn, LOW); for(offLed=0; offLed<(nonUsedAnodes+anodeNumber-1) && offLed<8; offLed++){ digitalWrite(serialAn1, LOW); digitalWrite(srclkAn1, HIGH); digitalWrite(srclkAn1, LOW); } for(onLed=0; onLed<(2-anodeNumber); onLed++){ digitalWrite(serialAn1, HIGH); digitalWrite(srclkAn1, HIGH); digitalWrite(srclkAn1, LOW); } for(offLed=0; offLed<(anodeNumber-2); offLed++){ digitalWrite(serialAn, LOW); digitalWrite(srclkAn, HIGH); digitalWrite(srclkAn, LOW); } for(onLed=0; onLed<1 && onLed<(anodeNumber-1); onLed++){ digitalWrite(serialAn, HIGH); digitalWrite(srclkAn, HIGH); digitalWrite(srclkAn, LOW); } for(offLed=0; offLed<(numberOfAnodes-anodeNumber); offLed++){ digitalWrite(serialAn, LOW); digitalWrite(srclkAn, HIGH); digitalWrite(srclkAn, LOW); } digitalWrite(rclkAn1, HIGH); digitalWrite(rclkAn, HIGH); //turning on the specific cathode layer digitalWrite(rclkCat, LOW); for(offLed=0; offLed<(cathodeLayer-1); offLed++){ digitalWrite(serialCat, HIGH); digitalWrite(srclkCat, HIGH); digitalWrite(srclkCat, LOW); } for(onLed=0; onLed<1; onLed++){ digitalWrite(serialCat, LOW); digitalWrite(srclkCat, HIGH); digitalWrite(srclkCat, LOW); } for(offLed=0; offLed<((numberOfLayers-cathodeLayer)+nonUsedCathodes); offLed++){ digitalWrite(serialCat, HIGH); digitalWrite(srclkCat, HIGH); digitalWrite(srclkCat, LOW); } digitalWrite(rclkCat, HIGH); delay(lightDuration); }//end of lightUpOneLed function