nissan200sx:

I dont have so many issues with the physical part of my electrical setup, its the programming thats difficult.
I know and can use ohm law, can connect the IC chips I have used so far in my builds, learnt binary for this project, but cant get my program optimized. I really want to remove the delay() feature abd use mills instead as delay slows the program Down and fills up the memory real quick.
The examples I have found uses digitalwrite, but need to use a void instead of a digital output.
Thanks
no problem we all start off with a very small tool box of code functions then as a project gets more complicated we start to look for better tools to use
take set up for example
yours did this
void setup() {
//set decoder pins to low
pinMode(p0, OUTPUT);
digitalWrite(p0, LOW);
pinMode(p1, OUTPUT);
digitalWrite(p0, LOW);
pinMode(p2, OUTPUT);
digitalWrite(p0, LOW);
pinMode(p3, OUTPUT);
digitalWrite(p0, LOW);
pinMode(p4, OUTPUT);
digitalWrite(p0, LOW);
pinMode(p5, OUTPUT);
digitalWrite(p0, LOW);
//set cathode pins to low
pinMode(Z0, OUTPUT);
digitalWrite(Z0, LOW);
pinMode(Z1, OUTPUT);
digitalWrite(Z1, LOW);
pinMode(Z2, OUTPUT);
digitalWrite(Z2, LOW);
pinMode(Z3, OUTPUT);
digitalWrite(Z3, LOW);
pinMode(Z4, OUTPUT);
digitalWrite(Z4, LOW);
pinMode(Z5, OUTPUT);
digitalWrite(Z5, LOW);
//enable decoders
pinMode(pEN, OUTPUT);
digitalWrite(pEN, HIGH);
}
theres nothing wrong with your set up but its a long way to write all the pins to OUTPUT and LOW
now I looked at that I though if the pins could assign a number to represent the real pin number then I could just repeat digitalWrite and pinmode instead
so I looked in the tool box and pulled out a array
byte ledArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13};
now the first point in the array is 0. so when I use the array and use 0 it will be changed by the program to 1, when I use 11 (remember we count 0 so 0 to 11 is 12 total) 11 will be changed to the last number in the array which is 13
now I can use a for to do most of the set up work for me
for (byte x = 0; x < 12; x = x + 1) {
//do this 12 times
pinMode (ledArray[x], OUTPUT);
digitalWrite(ledArray[x], LOW);
}
}
this for will make x change from 0 to 1 to 2 to 3 etc until 11
each time the x will be used in the pinmode line so its the same as saying
pinMode (array 0,OUTPUT);
pinMode (array 1,OUTPUT);
pinMode (array 2,OUTPUT);
as the number is referencing a array then
ledArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13}
then in real terms I have said
pinMode (array 0,OUTPUT); = pinMode (pin 1 ,OUTPUT);
pinMode (array 11,OUTPUT); = pinMode (pin 13 ,OUTPUT);
p.s remove the serial.begin(9600) line as that uses pin 0 and pin 1 it was something I used to test a idea that you shouldn't require, It may cause a problem later on
you should also see that I skipped the
pinMode(pEN, OUTPUT);
digitalWrite(pEN, HIGH);
as its just two lines of code then theres no real reason to make it complicated so they just need to be added back in the same way you had them