I am making a device which will have a button to measure the input and another button to reset and the inputs are variable analog values(0 to 5v) and output is a ratio of two analog input voltages. It also has a selection keys(two buttons) for four selections(like gain eg. if key1 == LOW key 2 == LOW then J = 1 and likewise) but the problem is when i am multiplying j with it the output shows zero if I multiply numbers like 1,2,3etc without using j then the ratio value gets multiplied.
here is the code
void setup() // put your setup code here, to run once:
{
Serial.begin(9600);
pinMode( K1, INPUT );
pinMode( K2, INPUT );
pinMode( MeasureButton, INPUT );
pinMode( ResetButton, INPUT );
dsp.begin(20, 4);
current = millis();
}
void loop()
{
while(current < wait)
{
Serial.println("INITIALIZING");
delay(1000);
current = millis();
}
Serial.println(" ");
delay(1000);
Serial.println(" READY TO MEASURE ");
delay(2000);
while (digitalRead(MeasureButton) == LOW)
{
if(K1 == LOW && K2 == LOW)
{J = 1; // SOMETHING VALUE
showMessage1();
i = 0;
delay(1000);
}if(K1 == LOW && K2 == HIGH)
J= 2; // SOMETHING VALUE
showMessage1();
i = 0;
delay(1000);
if(K1 == HIGH && K2 == LOW )
J= 3; // SOMETHING VALUE
showMessage1();
i = 0;
delay(1000);
if(K1 == HIGH && K2 == HIGH )
J= 4; // SOMETHING VALUE
showMessage1();
i = 0;
delay(1000);
}
while (digitalRead(ResetButton) == HIGH)
{
dsp.setCursor(1,0);
dsp.print(" ");
Serial.println(" ");
delay(1000);
dsp.setCursor(1,0);
dsp.print("RESETED");
Serial.println("RESETED");
delay(1000);
}
while (digitalRead(ResetButton) == LOW)
{
dsp.setCursor(1,0);
dsp.print(" ");
Serial.println(" ");
delay(1000);
dsp.setCursor(1,0);
dsp.print("PRESS MEASURE");
Serial.println("PRESS MEASURE");
delay(1000);
}
}
void showMessage1()
{
while(i<5)
{
A = analogRead(A0);
B = analogRead(A1);
C = analogRead(A2);
D = analogRead(A3);
N = analogRead(A4);
W1 = (A/N)*J; // J is another variable whose value is dependent on K selection values
W2 = (B/N)*J; // J is another variable whose value is dependent on K selection values
W3 = (C/N)*J; // J is another variable whose value is dependent on K selection values
W4 = (D/A)*J; // J is another variable whose value is dependent on K selection values
sumW1 = sumW1 + W1;
sumW2 = sumW2 + W2;
sumW3 = sumW3 + W3;
sumW4 = sumW4 + W4;
i++;
}
Serial.print("W1-");
Serial.print(sumW1);
Serial.print("W2-");
Serial.println(sumW2);
Serial.print("W3-");
Serial.print(sumW2);
Serial.print("W4-");
Serial.println(sumW4);
sumW1 = 0;
sumW2 = 0;
sumW3 = 0;
sumW4 = 0;
}