The project requires reading 35 Boolean yes/ no i/o pins
I want to iterate through them with an array. That would mean an array to specify the pin, an array to hold the status and an array to accept the appropriate value. I have been struggling and realize that I am hung up on the “”””char array_name [ ] = ( values ) “””” statement.
The standard approach: iterate through the fields with a variable in a ‘for’ statement.
I have the statements complete; I think. The ‘’int array_name etc ‘’’ works fine. The ‘’ char array_name” returns garbase. I am missing something.
I have reduced the code to the necessary parts. The first lines have an image of the project. The question is in the last lines. The char array; what am I missing?
And the Arduino project is
// I am unable to use an array with a char data type.I want to be able to reiterate throughthe
// i/o pins to read a boolean yes/no without using a bujnch of if statements
//these first lines are mostly to communicate the project. but the issue is seen at the end.
// my 'int arrays'are fine. the 'char array' is finding and returning garbage
// I have gone aroundand around on the details. quotes, end '/0' thing square brackets etc
// mostly no errors
#define ldrPin53 53
#define ldrPin52 52
#define ldrPin51 51
#define ldrPin50 50
#define ldrPin49 49
boolean ldrstatus53 = 0;
boolean ldrstatus52 = 0;
boolean ldrstatus51 = 0;
boolean ldrstatus50 = 0;
boolean ldrstatus49 = 0;
float loc_53 = 181.12;
float loc_52 = 179.04;
float loc_51 = 176.96;
float loc_50 = 174.88;
float loc_49 = 172.8;
int megaInputNumber = 1;
float primary_number = 16.7;
int i = 0;
/*
//pinMode (ldrPin53, INPUT);
pinMode (ldrPin52, INPUT);
pinMode (ldrPin51, INPUT);
pinMode (ldrPin50, INPUT);
pinMode (ldrPin49, INPUT);
*/
// hukmmm it reads the i/o pin, not the status!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 INPUT STATUS ARRAY. HODER FOR BOOLEAN Y/N THIS IS THE i/o ARRAY
char input_status[6] = { 'ldrstatus49','ldrstatus50','ldrstatus51','ldrstatus52','ldrstatus53' };
// THIS IS THE VALUE ARRAY
int value_array[6] = { 234,4556,1287,456 }; // this one eworks
// PIN_ID_ARRAY
char pin_id_array[6] = { ldrPin49,ldrPin50,ldrPin51,ldrPin52,ldrPin53 };
char char_array[7] = { 'ldrPin49','ldrPin50','ldrPin51','ldrPin52','ldrPin53' ,'\0' };
const char practicechar_array [5]= { '15','160','17','18','\0'}; // the const does not seem to help
//// the compier is ony seeing the ones place; one digit, on the right hwat?
// the \0 did not help
void setup() {
Serial.begin(9600);
Serial.println("hello world");
}
void loop() {
primary_number = 767676;
for ( int counter= 0; counter <5; counter++ ){
Serial.print ( " ok ");
Serial.println (value_array[counter] );//////// this one works
Serial.print ( " what ");
Serial.println (value_array[2]) ;
}
for ( int counter= 0; counter <5; counter++ ){
Serial.print ( " ok ");
Serial.println (practicechar_array[counter] );/////// this gives no error but garbage.. I see the last digit
Serial.print ( " what ");
Serial.println (practicechar_array[2]) ;
delay (2000);
}
}