SO I am trying to create a loop which will go to a new switch case each time but when ever I run the program on the serial monitor it just stays stuck in the same case
Shorting_algorithm.ino (5.23 KB)
SO I am trying to create a loop which will go to a new switch case each time but when ever I run the program on the serial monitor it just stays stuck in the same case
Shorting_algorithm.ino (5.23 KB)
#define TIMEOUT_T 2000
struct short_AnalogReading {
double val0;
double val1;
double val2;
double val3;
double val4;
double val5;
} *short_AnalogReading;
struct A_Reading {
double cellv0;
double cellv1;
double cellv2;
double cellv3;
double cellv4;
double cellv5;
} *A_Reading;
static int MuxPointer = 0;
static int modulePointer = 0;
void delay_short(unsigned int t, unsigned int p)
{
int i = 0;
while (i = 0, i < t, i++)
{
digitalWrite(p, HIGH);
Serial.print("."); //after 100ms
}
}
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT); //mod_0
pinMode(3, OUTPUT); //mod_1
pinMode(4, OUTPUT); //mod_2
pinMode(5, OUTPUT); //mod_3
pinMode(6, OUTPUT); //mod_4
pinMode(7, OUTPUT); //mod_5
pinMode(A0, INPUT); //mod_0 voltage reading
pinMode(A1, INPUT); //mod_1 voltage reading
pinMode(A2, INPUT); //mod_2 voltage reading
pinMode(A3, INPUT); //mod_3 voltage reading
pinMode(A4, INPUT); //mod_4 voltage reading
pinMode(A5, INPUT); //mod_5 voltage reading
Serial.begin(9600);
Serial.println("Startup complete");
}
void loop() {
if (MuxPointer < 5) { // check if Mux Pointer is within bounds
MuxPointer++; // reset to zero if not
}
switch (MuxPointer) { // lookup to assign PORT bits to Mux number
case 0:
digitalWrite(2, HIGH);
unsigned int i = 0;
short_AnalogReading->val0 = analogRead(A0); // read the input pin
Serial.println("Module 1 short begin");
delay_short(100, 2);
digitalWrite(2, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 1;
break;
MuxPointer++;
case 1:
short_AnalogReading->val1 = analogRead(A1); // read the input pin
Serial.println("Module 2 shorted");
delay_short(100, 3);
digitalWrite(3, HIGH);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 2;
break;
MuxPointer++;
case 2:
short_AnalogReading->val2 = analogRead(A2); // read the input pin
Serial.println("Module 3 shorted");
delay_short(100, 4);
digitalWrite(4, HIGH);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 3;
break;
MuxPointer++;
case 3:
short_AnalogReading->val3 = analogRead(A3); // read the input pin
Serial.println("Module 4 shorted");
delay_short(100, 5);
digitalWrite(5, HIGH);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 4;
break;
MuxPointer++;
case 4:
short_AnalogReading->val4 = analogRead(A4); // read the input pin
Serial.println("Module 4 shorted");
delay_short(100, 6);
digitalWrite(6, HIGH);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 5;
break;
MuxPointer++;
case 5:
short_AnalogReading->val5 = analogRead(A5); // read the input pin
Serial.println("Module 4 shorted");
delay_short(100, 7);
digitalWrite(7, HIGH);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 0;
break;
MuxPointer++;
}
static int modulePointer = 0;
if (modulePointer > 5) { // check if Mux Pointer is within bounds
modulePointer = 0; // reset to zero if not
}
switch (modulePointer) { // lookup to assign PORT bits to Mux number
case 0:
A_Reading->cellv0 = analogRead(A0); // read the input pin
Serial.println("Module 1 voltage");
int V_out0 = A_Reading->cellv0 ;
Serial.print(V_out0);
modulePointer = 1;
break;
case 1:
A_Reading->cellv1 = analogRead(A1); // read the input pin
Serial.println("Module 2 voltage");
int V_out1 = A_Reading->cellv1 ;
Serial.print(V_out1);
modulePointer = 2;
break;
case 2:
A_Reading->cellv2 = analogRead(A2); // read the input pin
Serial.println("Module 3 voltage");
int V_out2 = A_Reading->cellv2 ;
Serial.print(V_out2);
modulePointer = 3;
break;
case 3:
A_Reading->cellv3 = analogRead(A3); // read the input pin
Serial.println("Module 4 voltage");
int V_out3 = A_Reading->cellv2 ;
Serial.print(V_out3);
modulePointer = 4;
break;
case 4:
A_Reading->cellv4 = analogRead(A4); // read the input pin
Serial.println("Module 5 voltage");
int V_out4 = A_Reading->cellv4 ;
Serial.print(V_out4);
modulePointer = 5;
break;
case 5:
A_Reading->cellv5 = analogRead(A5); // read the input pin
Serial.println("Module 6 voltage");
int V_out5 = A_Reading->cellv5 ;
Serial.print(V_out5);
modulePointer = 0;
break;
}
}
MuxPointer = 1;
break;
MuxPointer++;
What do you think "break" does?
Please remember to use code tags when posting code.
It's probably not a good idea to give variables the same names that you've given to the structs.
more gross mis-uses of language ...
struct A_Reading {
double cellv0;
double cellv1;
double cellv2;
double cellv3;
double cellv4;
double cellv5;
} *A_Reading;
besides having the same name as the struct, A_Reading is a ptr. where is a variable of type A_Reading that it points to?
double cellv [6];
why is a struct being defined instead of a simple array?
if (MuxPointer < 5) { // check if Mux Pointer is within bounds
MuxPointer++; // reset to zero if not
}
.
.
.
MuxPointer = 1;
break;
why is MuxPointer set to a value in the case, but incremented elsewhere
... there are other problems
it's standard practice to only Capitalize constants, user variable types, ...
case 0:
digitalWrite(2, HIGH);
unsigned int i = 0;
This case has an initialized local variable so all of the cases after this point are unreachable. You should have gotten some warning messages. Try this:
case 0:
digitalWrite(2, HIGH);
unsigned int i; // Don't initialize the local variable in the declaration
i = 0; // Initialize the variable at run time.
or
case 0:
{ // Add brackets around the case contents to limit the scope of 'i'.
digitalWrite(2, HIGH);
unsigned int i = 0;
.
.
.
}
break;
johnwasser:
case 0:
digitalWrite(2, HIGH);
unsigned int i = 0;
This case has an initialized local variable so all of the cases after this point are unreachable. You should have gotten some warning messages. Try this:
case 0:
digitalWrite(2, HIGH);
unsigned int i; // Don't initialize the local variable in the declaration
i = 0; // Initialize the variable at run time.or
case 0:
{ // Add brackets around the case contents to limit the scope of 'i'.
digitalWrite(2, HIGH);
unsigned int i = 0;
.
.
.
}
break;
Thanks a lot I was able to resolve it tofr the first switch case statement but cant seem to figure out the problem now because everything looks all right.
#define TIMEOUT_T 2000
struct short_AnalogReading {
double val0;
double val1;
double val2;
double val3;
double val4;
double val5;
} *short_AnalogReading;
struct A_Reading {
double cellv0;
double cellv1;
double cellv2;
double cellv3;
double cellv4;
double cellv5;
} *A_Reading;
static int MuxPointer = 0;
static int modulePointer = 0;
void delay_short(unsigned int t, unsigned int p)
{
int i = 0;
while (i = 0, i < t, i++)
{
digitalWrite(p, HIGH);
Serial.print("."); //after 100ms
}
}
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT); //mod_0
pinMode(3, OUTPUT); //mod_1
pinMode(4, OUTPUT); //mod_2
pinMode(5, OUTPUT); //mod_3
pinMode(6, OUTPUT); //mod_4
pinMode(7, OUTPUT); //mod_5
pinMode(A0, INPUT); //mod_0 voltage reading
pinMode(A1, INPUT); //mod_1 voltage reading
pinMode(A2, INPUT); //mod_2 voltage reading
pinMode(A3, INPUT); //mod_3 voltage reading
pinMode(A4, INPUT); //mod_4 voltage reading
pinMode(A5, INPUT); //mod_5 voltage reading
Serial.begin(9600);
Serial.println("Startup complete");
}
void loop() {
switch (MuxPointer) { // lookup to assign PORT bits to Mux number
case 0:
// digitalWrite(2, HIGH);
short_AnalogReading->val0 = analogRead(A0); // read the input pin
Serial.println("Module 1 shorted");
delay_short(100, 2);
digitalWrite(2, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 1;
break;
case 1:
short_AnalogReading->val1 = analogRead(A1); // read the input pin
Serial.println("Module 2 shorted");
delay_short(100, 3);
digitalWrite(3, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 2;
break;
case 2:
short_AnalogReading->val2 = analogRead(A2); // read the input pin
Serial.println("Module 3 shorted");
delay_short(100, 4);
digitalWrite(4, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 3;
break;
case 3:
short_AnalogReading->val3 = analogRead(A3); // read the input pin
Serial.println("Module 4 shorted");
delay_short(100, 5);
digitalWrite(5, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 4;
break;
case 4:
short_AnalogReading->val4 = analogRead(A4); // read the input pin
Serial.println("Module 5 shorted");
delay_short(100, 6);
digitalWrite(6, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 5;
break;
case 5:
short_AnalogReading->val5 = analogRead(A5); // read the input pin
Serial.println("Module 6 shorted");
delay_short(100, 7);
digitalWrite(7, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 0;
break;
}
delay_short(1000, 0);
if (modulePointer > 5) { // check if Mux Pointer is within bounds
modulePointer = 0; // reset to zero if not
}
switch (modulePointer) { // lookup to assign PORT bits to Mux number
case 0:
A_Reading->cellv0 = analogRead(A0); // read the input pin
Serial.println("Module 1 voltage");
int V_out0 = A_Reading->cellv0 ;
Serial.print(V_out0);
modulePointer = 1;
break;
case 1:
A_Reading->cellv1 = analogRead(A1); // read the input pin
Serial.println("Module 2 voltage");
int V_out1 = A_Reading->cellv1 ;
Serial.print(V_out1);
modulePointer = 2;
break;
case 2:
A_Reading->cellv2 = analogRead(A2); // read the input pin
Serial.println("Module 3 voltage");
int V_out2 = A_Reading->cellv2 ;
Serial.print(V_out2);
modulePointer = 3;
break;
case 3:
A_Reading->cellv3 = analogRead(A3); // read the input pin
Serial.println("Module 4 voltage");
int V_out3 = A_Reading->cellv2 ;
Serial.print(V_out3);
modulePointer = 4;
break;
case 4:
A_Reading->cellv4 = analogRead(A4); // read the input pin
Serial.println("Module 5 voltage");
int V_out4 = A_Reading->cellv4 ;
Serial.print(V_out4);
modulePointer = 5;
break;
case 5:
A_Reading->cellv5 = analogRead(A5); // read the input pin
Serial.println("Module 6 voltage");
int V_out5 = A_Reading->cellv5 ;
Serial.print(V_out5);
modulePointer = 0;
break;
}
}
Now for the first switch case statement it doesn't seem to enter the last case and for the second switch case statement there seems to be the same problem as previously.
Well... there is the same problem in another switch statement:
case 0:
A_Reading->cellv0 = analogRead(A0); // read the input pin
Serial.println("Module 1 voltage");
int V_out0 = A_Reading->cellv0 ; ////////////////// INITIALIZED LOCAL VARIABLE. //////////////////
Serial.print(V_out0);
modulePointer = 1;
break;
You have still NOT corrected the issues already pointed out. You create POINTERS A_Reading and short_AnalogReading, but you never POINT them at valid memory. So when you write using those pointers, you are corrupting some random place in memory. And, every case in your second switch statement creates a local variable, without creating its own scope. Get in the habit of ALWAYS writing cases as:
case xxx:
{
// case code here
break;
}
RayLivingston:
You have still NOT corrected the issues already pointed out. You create POINTERS A_Reading and short_AnalogReading, but you never POINT them at valid memory. So when you write using those pointers, you are corrupting some random place in memory. And, every case in your second switch statement creates a local variable, without creating its own scope. Get in the habit of ALWAYS writing cases as:case xxx:
{
// case code here
break;
}
RayLivingston:
You have still NOT corrected the issues already pointed out. You create POINTERS A_Reading and short_AnalogReading, but you never POINT them at valid memory. So when you write using those pointers, you are corrupting some random place in memory. And, every case in your second switch statement creates a local variable, without creating its own scope. Get in the habit of ALWAYS writing cases as:case xxx:
{
// case code here
break;
}
AH really sorry about that and thank you guys soo much now I think this will probably be the last thing
#define TIMEOUT_T 2000
struct short_AnalogReading {
double val0;
double val1;
double val2;
double val3;
double val4;
double val5;
} *short_AnalogReading;
struct A_Reading {
double cellv0;
double cellv1;
double cellv2;
double cellv3;
double cellv4;
double cellv5;
} *A_Reading;
static int MuxPointer = 0;
static int modulePointer = 0;
void delay_short(unsigned int t, unsigned int p)
{
int i = 0;
while (i = 0, i < t, i++)
{
digitalWrite(p, HIGH);
Serial.print("."); //after 100ms
}
}
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT); //mod_0
pinMode(3, OUTPUT); //mod_1
pinMode(4, OUTPUT); //mod_2
pinMode(5, OUTPUT); //mod_3
pinMode(6, OUTPUT); //mod_4
pinMode(7, OUTPUT); //mod_5
pinMode(A0, INPUT); //mod_0 voltage reading
pinMode(A1, INPUT); //mod_1 voltage reading
pinMode(A2, INPUT); //mod_2 voltage reading
pinMode(A3, INPUT); //mod_3 voltage reading
pinMode(A4, INPUT); //mod_4 voltage reading
pinMode(A5, INPUT); //mod_5 voltage reading
Serial.begin(9600);
Serial.println("Startup complete");
}
void loop() {
switch (MuxPointer) { // lookup to assign PORT bits to Mux number
case 0:
// digitalWrite(2, HIGH);
short_AnalogReading->val0 = analogRead(A0); // read the input pin
Serial.println("Module 1 shorted");
delay_short(100, 2);
digitalWrite(2, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 1;
break;
case 1:
{
short_AnalogReading->val1 = analogRead(A1); // read the input pin
Serial.println("Module 2 shorted");
delay_short(100, 3);
digitalWrite(3, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 2;
break;
}
case 2:
{
short_AnalogReading->val2 = analogRead(A2); // read the input pin
Serial.println("Module 3 shorted");
delay_short(100, 4);
digitalWrite(4, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 3;
break;
}
case 3:
{
short_AnalogReading->val3 = analogRead(A3); // read the input pin
Serial.println("Module 4 shorted");
delay_short(100, 5);
digitalWrite(5, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 4;
break;
}
case 4:
{
short_AnalogReading->val4 = analogRead(A4); // read the input pin
Serial.println("Module 5 shorted");
delay_short(100, 6);
digitalWrite(6, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 5;
break;
}
case 5:
{
short_AnalogReading->val5 = analogRead(A5); // read the input pin
Serial.println("Module 6 shorted");
delay_short(100, 7);
digitalWrite(7, LOW);
//get the reading for voltage (pulse module short voltage)
MuxPointer = 0;
break;
}
}
delay_short(1000, 0);
if (modulePointer > 5) { // check if Mux Pointer is within bounds
modulePointer = 0; // reset to zero if not
}
switch (modulePointer) { // lookup to assign PORT bits to Mux number
case 0:
{
A_Reading->cellv0 = analogRead(A0); // read the input pin
Serial.println("Module 1 voltage");
int V_out0 = A_Reading->cellv0 ;
Serial.print(V_out0);
modulePointer = 1;
break;
}
case 1:
{
A_Reading->cellv1 = analogRead(A1); // read the input pin
Serial.println("Module 2 voltage");
int V_out1 = A_Reading->cellv1 ;
Serial.print(V_out1);
modulePointer = 2;
break;
}
case 2:
{
A_Reading->cellv2 = analogRead(A2); // read the input pin
Serial.println("Module 3 voltage");
int V_out2 = A_Reading->cellv2 ;
Serial.print(V_out2);
modulePointer = 3;
break;
}
case 3:
{
A_Reading->cellv3 = analogRead(A3); // read the input pin
Serial.println("Module 4 voltage");
int V_out3 = A_Reading->cellv2 ;
Serial.print(V_out3);
modulePointer = 4;
break;
}
case 4:
{
A_Reading->cellv4 = analogRead(A4); // read the input pin
Serial.println("Module 5 voltage");
int V_out4 = A_Reading->cellv4 ;
Serial.print(V_out4);
modulePointer = 5;
break;
}
case 5:
{
A_Reading->cellv5 = analogRead(A5); // read the input pin
Serial.println("Module 6 voltage");
int V_out5 = A_Reading->cellv5 ;
Serial.print(V_out5);
modulePointer = 0;
break;
}
}
}
It doesn't seem to enter the last two cases in either of the switch cases and I think I should be out of your hair after this
This is getting tedious....
struct short_AnalogReading {
double val0;
double val1;
double val2;
double val3;
double val4;
double val5;
} *short_AnalogReading;
struct A_Reading {
double cellv0;
double cellv1;
double cellv2;
double cellv3;
double cellv4;
double cellv5;
} *A_Reading;
These are pointers, that point to NOTHING. BEFORE you can use these pointers, you must point them to valid structures. Why are you using pointers anyway? Just create global structures, and directly write them. Pointer should be left for when they are REALLY needed, they provide some advantage, and you understand how to use them properly. I see no need, and no advantage here, and you clearly do not understand how to properly use them, as this is the third time this mistake is being pointed out.
This is getting tedious....
struct short_AnalogReading {
double val0;
double val1;
double val2;
double val3;
double val4;
double val5;
} *short_AnalogReading;
struct A_Reading {
double cellv0;
double cellv1;
double cellv2;
double cellv3;
double cellv4;
double cellv5;
} *A_Reading;
These are pointers, that point to NOTHING. There are NO structures being created, only uninitialized pointers. BEFORE you can use these pointers, you must point them to valid structures. Why are you using pointers anyway? Just create global structures, and directly write them. Pointer should be left for when they are REALLY needed, they provide some advantage, and you understand how to use them properly. I see no need, and no advantage here, and you clearly do not understand how to properly use them, as this is the third time this mistake is being pointed out.
RayLivingston:
This is getting tedious....struct short_AnalogReading {
double val0;
double val1;
double val2;
double val3;
double val4;
double val5;
} *short_AnalogReading;
struct A_Reading {
double cellv0;
double cellv1;
double cellv2;
double cellv3;
double cellv4;
double cellv5;
} *A_Reading;
These are pointers, that point to NOTHING. There are NO structures being created, only uninitialized pointers. BEFORE you can use these pointers, you must point them to valid structures. Why are you using pointers anyway? Just create global structures, and directly write them. Pointer should be left for when they are REALLY needed, they provide some advantage, and you understand how to use them properly. I see no need, and no advantage here, and you clearly do not understand how to properly use them, as this is the third time this mistake is being pointed out.
RayLivingston:
This is getting tedious....struct short_AnalogReading {
double val0;
double val1;
double val2;
double val3;
double val4;
double val5;
} *short_AnalogReading;
struct A_Reading {
double cellv0;
double cellv1;
double cellv2;
double cellv3;
double cellv4;
double cellv5;
} *A_Reading;
These are pointers, that point to NOTHING. There are NO structures being created, only uninitialized pointers. BEFORE you can use these pointers, you must point them to valid structures. Why are you using pointers anyway? Just create global structures, and directly write them. Pointer should be left for when they are REALLY needed, they provide some advantage, and you understand how to use them properly. I see no need, and no advantage here, and you clearly do not understand how to properly use them, as this is the third time this mistake is being pointed out.
case 5:
{
A_Reading->cellv5 = analogRead(A5); // using pointer
Serial.println("Module 6 voltage");
int V_out5 = A_Reading->cellv5 ; // using pointer
Serial.print(V_out5);
modulePointer = 0;
break;
}
so does this not count as using it ???? really sorry about making it tedious for you
mudassirahmed:
case 5:
{
A_Reading->cellv5 = analogRead(A5); // using pointer
Serial.println("Module 6 voltage");
int V_out5 = A_Reading->cellv5 ; // using pointer
Serial.print(V_out5);
modulePointer = 0;
break;
}
so does this not count as using it ???? really sorry about making it tedious for you
Yes. You are using a pointer that has NOT BEEN INITIALIZED!!!
mudassirahmed:
case 5:
{
A_Reading->cellv5 = analogRead(A5); // using pointer
Serial.println("Module 6 voltage");
int V_out5 = A_Reading->cellv5 ; // using pointer
Serial.print(V_out5);
modulePointer = 0;
break;
}
so does this not count as using it ???? really sorry about making it tedious for you
Q: WHAT structure that pointer is pointing to?
A: It isn't writing to any structure, because you never created any structures, and you also never set the pointer to POINT to any structure. So when you run "A_Reading->cellv5 = analogRead(A5);", you have absolutely no idea where in RAM it is writing! The value returned by analogRead(A5) is written SOMEWHERE in RAM, but you have NO idea where, since you have not set the pointer to point to anything! It could be writing over your interrupt vectors, or your stack, or your heap, or your other variables, or anywhere at all. You are scribbling in some random place in memory that you do not own. That never ends well.
Again, there is no reason to be using pointers at all. Create the structures as globals, and write/read them directly. Using pointers gains you nothing. It saves no RAM (in fact, just the opposite), it gains nothing in performance, nor does it in any way simplify the code.
void delay_short(unsigned int t, unsigned int p)
{
int i = 0;
while (i = 0, i < t, i++)
{
digitalWrite(p, HIGH);
Serial.print("."); //after 100ms
}
}
I don't know what you intended for this to do but I don't think it does that. It looks like you were trying to write a 'for' loop but used the 'while' keyword and, since the semicolons in a 'for' loop argument list are not valid in a 'while' loop, you changed them to commas.
What you have, I think, is functionally equivalent to:
void delay_short(unsigned int t, unsigned int p)
{
int i = 0;
i = 0;
i < t;
while (i)
{
i++;
digitalWrite(p, HIGH);
Serial.print("."); //after 100ms
i = 0;
i < t;
}
}
Which, in turn, is equivalent to:
void delay_short(unsigned int t, unsigned int p)
{
}
In other words, your function does nothing.
there are numerous gross errors. the code won't compile. don't understand why a struct and a undefined variable to that structure is used to record readings that are not used elsewhere except to immediately print the value.
it appears that the code sequentially
reads an analog input
sets an output pin HIGH
attempts to delay a specified amount of time
sets the output LOW
reads an analog input and
prints the analog measurement
the code suggests the measuring/recording/printing the voltage before and after shorting the cell
i believe following will do the above. it's easier using arrays of pins. values saved in readings [] are unused.
byte pinOuts [] = { 2, 3, 4, 5, 6, 7 };
byte pinInps [] = { A0, A1, A2, A3, A4, A5 };
#define N_PINS sizeof(pinOuts)
int readings [N_PINS];
unsigned idx = 0;
// -----------------------------------------------------------------------------
void delay_short (
unsigned int t,
unsigned int p)
{
digitalWrite(p, HIGH);
delay (t);
digitalWrite(p, LOW);
}
// -----------------------------------------------------------------------------
void setup()
{
for (unsigned n = 0; n < N_PINS; n++) {
pinMode (pinOuts [n], OUTPUT);
pinMode (pinInps [n], INPUT);
}
Serial.begin(9600);
Serial.println("Startup complete");
}
// -----------------------------------------------------------------------------
void loop()
{
Serial.print ("Module ");
Serial.print (idx);
// read voltage
readings [idx] = analogRead (pinInps [idx]);
// short cell
delay_short (100, pinOuts [idx]);
delay (1000);
// read and print voltage
Serial.print (" voltage ");
Serial.println (analogRead (pinInps [idx]));
// advance to next pin
if (N_PINS < ++idx)
idx = 0;
}
it produces the following
Startup complete
Module 0 voltage 566
Module 1 voltage 1023
Module 2 voltage 1023
Module 3 voltage 1023
Module 4 voltage 400
Module 5 voltage 356
Module 6 voltage 344
Module 0 voltage 601
Module 1 voltage 1023
Module 2 voltage 1023
Module 3 voltage 1023
Module 4 voltage 349
Module 5 voltage 310
Module 6 voltage 346
Module 0 voltage 601
Module 1 voltage 1023
Module 2 voltage 0
Module 3 voltage 1023
Module 4 voltage 1023
Module 5 voltage 900
Module 6 voltage 917
it would be interesting to get an explanation? (try using google to translate this as well as a response)
167
Thanks a ton!
*I actually looked it up and understood that the random values in showing up when the analog pins not being used were because they were just picking up the noise on the board since there were no analog inputs. if that was what you were expecting me to look up on google ? *
Honestly I do appreciate the time you took the rewrite the code I will definitely use it to improve and already made modifications to it to make use of the values being stored in readings[].
gcjr:
lack of understanding
mudassirahmed:
I actually looked it up and understood that the random values in showing up when the analog pins not being used were because they were just picking up the noise on the board since there were no analog inputs.
how is this possible, the code your posted doesn't compile?