Hello everyone,
With some help from another forum and some research ive got the code working.
Ive found out about some techniques that make the code a lot quicker!
If you're wondering what i have changed, here is the code:
int analogPin = A0; // read from multiplexer using analog input 0
int strobePin = 8; // strobe is attached to digital pin 2
int MSGResetPin = 9; // reset is attached to digital pin 3
int spectrumValue; // to hold a2d values
int clockPins[7] = {52, 50, 48, 46, 44, 42, 40 };
int resetPins[7] = {53, 51, 49, 47, 45, 43, 41 };
int band[7];
void setup()
{
pinMode(analogPin, INPUT);
pinMode(strobePin, OUTPUT);
pinMode(MSGResetPin, OUTPUT);
pinMode(clockPins[7], OUTPUT);
pinMode(resetPins[7], OUTPUT);
digitalWrite(MSGResetPin, LOW);
digitalWrite(strobePin, HIGH);
}
void loop()
{
for ( int j = 0; j < 7; j++)
{
pinMode(clockPins[j], OUTPUT);
pinMode(resetPins[j], OUTPUT);
digitalWrite(MSGResetPin, HIGH);
digitalWrite(MSGResetPin, LOW);
digitalWrite(strobePin, LOW);
spectrumValue = analogRead(analogPin);
int PWMvalue = spectrumValue / 40; // scale analogRead's value to Write's 25 max
band[j] = PWMvalue;
for (int var1 = 0; var1 < band[j]; var1 = var1 + 1) {
Pulse(clockPins[j]);
}
Pulse(resetPins[j]);
}
digitalWrite(strobePin, HIGH);
}
void Pulse(int pin) {
digitalWrite(pin, HIGH);
digitalWrite(pin, LOW);
}