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 ();
}