Storing values into Array and using said values as outputs

Greetings! So I have been attempting to store PWM values in my Arduino as an array, then send the values out through a PWM wave to a demultiplexer which is controlled based on the strobe frequency of the input PWM signal as measured by the Arduino. The array is based on seven columns of values. Currently, I am using the demultiplexer to separate each value to a different output.

int strobePin = 7;
int resetPin = 8;
int outPin = A5;
int level[7];
int MainSignal = 10;
int A = 11;
int B = 12;
int C = 13;

void setup() {
    Serial.begin (9600);

    pinMode (strobePin, OUTPUT);
    pinMode (resetPin, OUTPUT);
    pinMode (outPin, INPUT);

    digitalWrite (resetPin, LOW);
    digitalWrite (strobePin, LOW);
    delay (1);

    digitalWrite (resetPin, HIGH);
    delay (1);
    digitalWrite (resetPin, LOW);
    digitalWrite (strobePin, HIGH);
   
    delay (1);

    pinMode (C, OUTPUT);
    pinMode (B, OUTPUT);
    pinMode (A, OUTPUT);
    pinMode (MainSignal, OUTPUT);

    digitalWrite (A, LOW); 
    digitalWrite (B, LOW); 
    digitalWrite (C, LOW);
    delay (1); 

    }
void loop() {

  for (int i = 0; i < 7; i++) {
    digitalWrite (strobePin, LOW);
    delayMicroseconds (100);
  
    level[i] = analogRead(outPin) / 5;
    digitalWrite (strobePin, HIGH);
    delayMicroseconds (100);

    int Audio = analogRead(A5) / 5; 
      analogWrite(MainSignal, Audio);

       
    if (i == 0) { 
      digitalWrite (A, HIGH); 
      digitalWrite (B, LOW); 
      digitalWrite (C, LOW);
    } 
    else if (i == 1) { 
      digitalWrite (A, LOW);
      digitalWrite (B, HIGH);
      digitalWrite (C, LOW);
    }
    else if (i == 2) {
      digitalWrite (A, HIGH);
      digitalWrite (B, HIGH);
      digitalWrite (C, LOW);
    } 
    else if (i == 3) {
      digitalWrite (A, LOW);
      digitalWrite (B, LOW);
      digitalWrite (C, HIGH);
    }
    else if (i == 4) {
      digitalWrite (A, HIGH);
      digitalWrite (B, LOW);
      digitalWrite (C, HIGH);
    }
    else if (i == 5) {
      digitalWrite (A, LOW);
      digitalWrite (B, HIGH);
      digitalWrite (C, HIGH);
    }
    else if (i == 6) {
      digitalWrite (A, HIGH);
      digitalWrite (B, HIGH);
      digitalWrite (C, HIGH);
    }

    delayMicroseconds (100);

  }

  for (int i = 0; i < 7; i++) {
    Serial.print (level[i]);
    Serial.print ("   ");
    delayMicroseconds (200);
  }
  
  delay (50);
  Serial.println ();
  
}

This above code creates a seven segment array as seen in the photo attached through the link below. It sends these values out through a new PWM wave in one output dubbed MainSignal

However, I would like to be able to instead store each (most recent) value of each column, and instead of sending the values of the whole row out through one output as a PWM wave, I would instead like to have each value be sent as an analogWrite function that is distinct through each band. Each to correspond to their own output. Ideally, this would make it so there are seven values being outputted at all times, all the most recent value in the array for their respective column. Whenever a new value is created in the column, the output for that band (aka column) changes to the most recent value. Hence the seven active outputs instead of just the one. Hence using the Arduino itself as a demultiplexer, but one that makes it possible for all signals from all seven values to be active instead of just one at a time, switching between them.

I thought about doing something like this code featured below, however I couldn't get it to work. Hoping someone might have feedback on how to accomplish my goal or if it is even possible.

int strobePin = 12;
int resetPin = 13;
int outPin = A5;
int level[7];
int FirstBandOutput = 10;
int SecondBandOutput = 9;
int ThirdBandOutput = 8;
int FourthBandOutput = 7;
int FifthBandOutput = 6;
int SixthBandOutput = 5;
int SeventhBandOutput = 4;


void setup() {
    Serial.begin (9600);

    pinMode (strobePin, OUTPUT);
    pinMode (resetPin, OUTPUT);
    pinMode (outPin, INPUT);

    digitalWrite (resetPin, LOW);
    digitalWrite (strobePin, LOW);
    delay (1);

    digitalWrite (resetPin, HIGH);
    delay (1);
    digitalWrite (resetPin, LOW);
    digitalWrite (strobePin, HIGH);
   
    delay (1);

    pinMode (FirstBandOutput, OUTPUT);
    pinMode (SecondBandOutput, OUTPUT);
    pinMode (ThirdBandOutput, OUTPUT);
    pinMode (FourthBandOutput, OUTPUT);
    pinMode (FifthBandOutput, OUTPUT);
    pinMode (SixthBandOutput, OUTPUT);
    pinMode (SeventhBandOutput, OUTPUT);

    delay (1); 

    }

void loop() {

  for (int i = 0; i < 7; i++) {
    digitalWrite (strobePin, LOW);
    delayMicroseconds (100);

    level[i] = analogRead(outPin) / 5;

    digitalWrite (strobePin, HIGH);
    delayMicroseconds (100);

    if (i == 0) { 
      int FirstBandAudio = analogRead(A5) / 5;
    } 
    else if (i == 1) { 
      int SecondBandAudio = analogRead(A5) / 5;
    }
    else if (i == 2) {
      int ThirdBandAudio = analogRead(A5) / 5;
    } 
    else if (i == 3) {
      int FourthBandAudio = analogRead(A5) / 5;
    }
    else if (i == 4) {
      int FifthBandAudio = analogRead(A5) / 5;
    }
    else if (i == 5) {
      int SixthBandAudio = analogRead(A5) / 5;
    }
    else if (i == 6) {
      int SeventhBandAudio = analogRead(A5) / 5;
    }

    analogWrite(FirstBandOutput, FirstBandAudio);
    analogWrite(SecondBandOutput, SecondBandAudio);
    analogWrite(ThirdBandOutput, ThirdBandAudio);
    analogWrite(FourthBandOutput, FourthBandAudio);
    analogWrite(FifthBandOutput, FifthBandAudio);
    analogWrite(SixthBandOutput, SixthBandAudio);
    analogWrite(SeventhBandOutput, SeventhBandAudio);

    delayMicroseconds (100);

  }

  for (int i = 0; i < 7; i++) {
    Serial.print (level[i]);
    Serial.print ("   ");
    delayMicroseconds (200);
  }

  delay (50);
  Serial.println ();

}

Please show a circuit diagram or describe better what is sent how. I only can guess that ABC form a multiplexer address, but how is PWM related to the transmitted values?

Click on the imgur link above for image and description.

Update:
Cut off by a watermark in the image I said this: "This value [pointing to the first out of seven square waves in the PWM signal cycle] is to be stored [in an array potentially], and then that stored value is to be outputted from an Arduino output using analogWrite. That output is continuously outputting a signal until the cycle repeats and a new value for the first out of seven square waves in the PWM signal is read and stored, at which point it replaces the outputted value for the new one".

The reason why I need this is because the CD4051 demultiplexer only redirects the signal to one of 7 outputs, hence only one output can be on at a time. I need every one of the seven outputs to be on at all times and constantly updating with each new cycle.

I think that you don't really understand PWM. A PWM signal is dynamic, digital and can not simply be read by analogRead() nor can it be stored in an analog multiplexer. A PWM signal can be converted into an analog voltage by a low pass filter, not immediately nor persistent.

Likewise. I don't think you understand the mechanisms of such. Because I clearly have gotten it to work as evidenced by the array I have shown above. Go ahead. Try the first code I submitted. It will work. I am using an MSGEQ7 to get the PWM Wave, and then it's outputs are stored into the array I showed you. If you're going to talk about "what a PWM wave is", you're not being very helpful. I'm asking if anyone knows how to use my stored values from my array to make an output unique to each column that updates with every new input into said column.

Step 1: how does your output signal look like?
Step 2: what kind of circuit can store that signal?

Have you had a look at multi-channel RC for transmission of multiple analog signals over a single channel, w/out a wire?

The output is what is shown in the array. A voltage value corresponding to 5V multiplied by the value shown divided by 255. I am not looking to make a new circuit or add new circuit elements. I am hoping to get the Arduino to store the signal. The time between signal pulses of each cycle is too long to be able to store the signal in any analog circuit elements like capacitors and such. Looking for a coding solution, not hardware. One such thing may not exist. I'm not sure. Here to ask about that, to see if possible, and if so if anyone has any ideas.

The 4051 can not do what you want. Chose another hardware, then write the software for it.

The MSGEQ7 does not give you PWM values. It gives you a level corresponding to each of 7 frequency bands. If you want to map each level linearly to a PWM level for the analogWrite() function you can just use the map() function, something like this:

spectrumLevel = analogRead(outPin); 
pwmOut[i] = map(spectrumLevel, 0, 1024, 0, 255);

Arduino UNO does not have enough PWM outputs. You will have to use a Mega.

This code does not compile. You created local copies of your band values here. In other words their scope is limited to each if code block. Also you are reading the levels from A5 AFTER you set the strobe back to HIGH.

    if (i == 0) { 
      int FirstBandAudio = analogRead(A5) / 5;
    } 
    else if (i == 1) { 
      int SecondBandAudio = analogRead(A5) / 5;
    }
    else if (i == 2) {
      int ThirdBandAudio = analogRead(A5) / 5;
    } 
    else if (i == 3) {
      int FourthBandAudio = analogRead(A5) / 5;
    }
    else if (i == 4) {
      int FifthBandAudio = analogRead(A5) / 5;
    }
    else if (i == 5) {
      int SixthBandAudio = analogRead(A5) / 5;
    }
    else if (i == 6) {
      int SeventhBandAudio = analogRead(A5) / 5;
    }

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.