So I'm working on a way to display what mode I have selected on 9 individual LEDs. I want to convert the number to binary and then write it on the LEDs. I've been working on this for literally hours and there just has to be an easy way to do this. Heres what I have so far, its really badly worded I think and it doesn't work, mostly because of the mixed data types Im using.
int pinArray[] = {2,3,4,5,6,7,8,12,13};
int binaryArray0[] = {0,0,0,0,0,0,0,0,0};
int binaryArray1[] = {0,0,0,0,0,0,0,0,1};
int binaryArray2[] = {0,0,0,0,0,0,0,1,0};
int binaryArray3[] = {0,0,0,0,0,0,0,1,1};
int binaryArray4[] = {0,0,0,0,0,0,1,0,0};
int binaryArray5[] = {0,0,0,0,0,0,1,0,1};
int binaryArray6[] = {0,0,0,0,0,0,1,1,0};
int binaryArray7[] = {0,0,0,0,0,0,1,1,1};
int binaryArray8[] = {0,0,0,0,0,1,0,0,0};
int binaryArray9[] = {0,0,0,0,0,1,0,0,1};
int binaryArray10[] = {0,0,0,0,0,1,0,1,0};
int binaryArray11[] = {0,0,0,0,0,1,0,1,1};
int binaryArray12[] = {0,0,0,0,0,1,1,0,0};
int binaryArray13[] = {0,0,0,0,0,1,1,0,1};
int binaryArray14[] = {0,0,0,0,0,1,1,1,0};
int binaryArray15[] = {0,0,0,0,0,1,1,1,1};
int binaryArray16[] = {0,0,0,0,1,0,0,0,0};
int binaryArray17[] = {0,0,0,0,1,0,0,0,1};
int binaryArray18[] = {0,0,0,0,1,0,0,1,0};
int binaryArray19[] = {0,0,0,0,1,0,0,1,1};
int binaryArray20[] = {0,0,0,0,1,0,1,0,0};
int binaryArray21[] = {0,0,0,0,1,0,1,0,1};
int binaryArray22[] = {0,0,0,0,1,0,1,1,0};
int binaryArray23[] = {0,0,0,0,1,0,1,1,1};
int binaryArray24[] = {0,0,0,0,1,1,0,0,0};
int binaryArray25[] = {0,0,0,0,1,1,0,0,1};
int binaryArray26[] = {0,0,0,0,1,1,0,1,0};
int binaryArray27[] = {0,0,0,0,1,1,0,1,1};
int binaryArray28[] = {0,0,0,0,1,1,1,0,0};
int binaryArray29[] = {0,0,0,0,1,1,1,0,1};
int binaryArray30[] = {0,0,0,0,1,1,1,1,0};
int binaryArray31[] = {0,0,0,0,1,1,1,1,1};
int binaryArray32[] = {0,0,0,1,0,0,0,0,0};
int binaryArray33[] = {0,0,0,1,0,0,0,0,1};
int binaryArray34[] = {0,0,0,1,0,0,0,1,0};
int binaryArray35[] = {0,0,0,1,0,0,0,1,1};
int binaryArray36[] = {0,0,0,1,0,0,1,0,0};
void setup(){
Serial.begin(9600);
for (int count = 0; count <8; count++){
pinMode(pinArray[count],OUTPUT);
}
}
int BINwrite(int a){
for (int count = 0; count < 9; count++){
digitalWrite(pinArray[count], LOW);
}
String string1 = "binaryArray";
String string2 = a;
String binArray = string1 + string2;
if(binArray[0] == 1) digitalWrite(pinArray[0], HIGH);
if(binArray[1] == 1) digitalWrite(pinArray[1], HIGH);
if(binArray[2] == 1) digitalWrite(pinArray[2], HIGH);
if(binArray[3] == 1) digitalWrite(pinArray[3], HIGH);
if(binArray[4] == 1) digitalWrite(pinArray[4], HIGH);
if(binArray[5] == 1) digitalWrite(pinArray[5], HIGH);
if(binArray[6] == 1) digitalWrite(pinArray[6], HIGH);
if(binArray[7] == 1) digitalWrite(pinArray[7], HIGH);
if(binArray[8] == 1) digitalWrite(pinArray[8], HIGH);
delay(2);
}
void loop(){
for (int count = 0; count <37; count++){
BINwrite(count);
}
}
This is all just a test version and once I get it figured out I will put it in the rest of the code. Im trying to make a function that does this for me so that I can use it a bunch of times. I have the loop just running the function with different values for testing purposes. The adding of the strings bit works great and spits out the right name for the array variables but it doesn't work when it goes through my if statements. I'm guessing its because its looking at it like a string and not a variable name so its just not analyzing it right. I've tries a bunch of different methods and just not having luck, this was the most promising.
I guess another way you could do it would be to give it a String of values (like 00010100) and have it look at each individual character and assign it to a variable or maybe just use it in the if statement to skip a step.