1

This posting contains 2 sketches. the analogmux1 compiles successfully. Concerning analogmuvvolts sketch an error stating updateMux1 was not declared in this scope results. The int Mux1_State [8] = 0: is defined exactly the same in both however the error results.

I'm learning Arduino programming so there are other errors in the sketch. What I'm trying to accomplish is to display the actual voltage of each channel, not numbers which appear in the analogMux.

It would be appreciated if the community could provide me with some guidance.

Analogmux:

int pin_Out_S0 = 8;
int pin_Out_S1 = 9;
int pin_Out_S2 = 10;
int pin_In_Mux1 = A0;
int Mux1_State[8] = {0};
void setup() {
 pinMode(pin_Out_S0, OUTPUT);
 pinMode(pin_Out_S1, OUTPUT);
 pinMode(pin_Out_S2, OUTPUT);
 //pinMode(pin_In_Mux1, INPUT);
 Serial.begin(9600);
}
void loop() {
 updateMux1();
 for(int i = 0; i < 8; i ++) {
 if(i == 7) {
 Serial.println(Mux1_State[i]);
 } else {
 Serial.print(Mux1_State[i]);
 Serial.print(",");
 }
 }
}
void updateMux1 () {
 for (int i = 0; i < 8; i++){
 digitalWrite(pin_Out_S0, HIGH && (i & B00000001));
 digitalWrite(pin_Out_S1, HIGH && (i & B00000010));
 digitalWrite(pin_Out_S2, HIGH && (i & B00000100));
 Mux1_State[i] = analogRead(pin_In_Mux1);
 }
}

And analogmuxvolts

int pin_Out_S0 = 8;
int pin_Out_S1 = 9;
int pin_Out_S2 = 10;
int pin_In_Mux1 = A0;
int Mux1_State[8] = {0};
//float Mux1_State[i] =0;
int RawValue=0;
float Voltage = 0;
void setup() {
 pinMode(pin_Out_S0, OUTPUT);
 pinMode(pin_Out_S1, OUTPUT);
 pinMode(pin_Out_S2, OUTPUT);
 pinMode(pin_In_Mux1, INPUT);
 Serial.begin(9600);
}
void loop() {
 RawValue = analogRead(pin_In_Mux1);
 Voltage = (RawValue * 5.0) / 1024; //scale the ADC
 updateMux1();
 Serial.println(Mux1_State);
 for(int i = 0; i < 8; i ++) {
 if(i == 7) {
 Serial.println(Mux1_State[i]);
 } else {
 Serial.print(Mux1_State[i]);
 Serial.print(",");
 //vout = (value * 5.0) / 1024.0;
 }
 }
 Serial.print("Raw Value = " );
 Serial.print(RawValue); 
}
Dave X
2,35015 silver badges29 bronze badges
asked Mar 7, 2016 at 3:11
2
  • Is updateMux1() not in the second sketch? Commented Mar 7, 2016 at 3:19
  • The error is updateMux1' was not declared in this scope and indeed that function is not in the second sketch. Commented Mar 7, 2016 at 4:05

1 Answer 1

1

Declare the updateMux() function by copying it from your first sketch into your second sketch:

void updateMux1 () {
 for (int i = 0; i < 8; i++){
 digitalWrite(pin_Out_S0, HIGH && (i & B00000001));
 digitalWrite(pin_Out_S1, HIGH && (i & B00000010));
 digitalWrite(pin_Out_S2, HIGH && (i & B00000100));
 Mux1_State[i] = analogRead(pin_In_Mux1);
 }
}

And do the conversions on the stored Mux1_State[] values during printing like:

 for(int i = 0; i < 8; i ++) {
 Serial.println(Mux1_State[i]*5.0/1024.0);
 if(i == 7) { 
 Serial.println();
 } else { 
 Serial.print(",");
 }
 }
answered Mar 7, 2016 at 5:01
1
  • I appreciate your help Dave. Tom Commented Mar 8, 2016 at 5:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.