Hi,
I'm trying to send Arduino a list from Pure Data, in order to have several LEDs on (or off) from a multiplexer. I know this isn't the section for multiplexing, but my problem for now lies in the declaration of a variable, so I thought of posting here. My code is this (the actual problem occurs in the loop but I'm including the setup of the code as well for definition and variable declaration clarification; you can as well skip this)
#define CONTROL0 2
#define CONTROL1 3
#define CONTROL2 4
#define CONTROL3 5
const int muxLed = A0;
int i = 0;
void setup() {
Serial.begin(9600);
pinMode(CONTROL0, OUTPUT);
pinMode(CONTROL1, OUTPUT);
pinMode(CONTROL2, OUTPUT);
pinMode(CONTROL3, OUTPUT);
pinMode(muxLed, OUTPUT);
}
Here is where the problem occurs
void loop() {
if (Serial.available() > 0) {
i = Serial.read();
if (i>16) {
int j = i - 16; /* I don't really know how to distinguish data that I send
from my computer, therefore I set different number ranges and correct with
an offset in the arduino code */
int myLeds[j];
}
if (i>=0 && i<16) {
for (int k = 0; k < j; k++) { // here is where the problem occurs, even though I've already declared j earlier
myLeds[k] == i;
digitalWrite(CONTROL0, (myLeds[k]&15)>>3); /* here I want to read the array elements one by one, maybe another for loop is needed.. */
digitalWrite(CONTROL1, (myLeds[k]&7)>>2);
digitalWrite(CONTROL2, (myLeds[k]&3)>>1);
digitalWrite(CONTROL3, (myLeds[k]&1));
digitalWrite(muxLed, HIGH);
} else {
digitalWrite(muxLed, LOW);
}
}
}
}
I get the following error
'j' was not declared in this scope
What I want to do is first send the length of my list to set it as an array length, and then set the elements of the array. Finally I want to read the array's elements one by one in a for loop.
Any help appreciated.