Dear friends,
I am generating a staircase voltage ramp from a WaveDAC facility provided by PSOC 5LP 888 97 device fron Cypress Semiconductor incorporation and detecting its voltage by Arduino UNO using alaogRead (A0);. My actual objective is to take one reading when voltage is" stable" and" downstairs" say S1 while another reading when voltage is "stable" and "upstairs" say S2 and taking difference of both readings that is (S2 -S1). For this purpose I wrote an Arduino code that acquire 10 or more analogReadings and find just maximum and minimum of those and make subtraction to print differential voltage. However, the problem is my code only gives only one differential reading and keep showing the same even after running for minutes and don't gives next differential. while running the basic "Serial analogRead" example I confirmed that it gives nice staircase output ramp as produced by PSOC WaveDac. my voltage ramp is attached here along with the code. Kindly help me in this regard and if there is a better approach for solving this problem I am thankful as I am very new to programming.
l.
DPV_simple_with_time_and_min_and_max.ino (1.2 KB)
int max =0;
int min=1023;
int sV[9]={0,0,0,0,0,0,0,0,0};
int diff;
int i=0;
int new_Value;
int Start_increamenter;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial);
new_Value=0;
Start_increamenter=0;
new_Value=0;
}
void loop() {
// put your main code here, to run repeatedly:
new_Value=analogRead(A0);
if(Start_increamenter<=9){
sV[9]=sV[8];
sV[8]=sV[7];
sV[7]=sV[6];
sV[6]=sV[5];
sV[5]=sV[4];
sV[4]=sV[3];
sV[3]=sV[2];
sV[2]=sV[1];
sV[1]=sV[0];
sV[0]=new_Value;
Start_increamenter++;
}
else
{
min=1023;
for(i=0;i<=9;i++){
if(sV[i]<min){
min=sV[i];
Serial.println("min");
Serial.println(min);
}
max=0;
for(i=0;i<=9;i++){
if(sV[i]>max){
max=sV[i];
Serial.println("max");
Serial.println(max);
}
if(max/min>1.05){
diff= max - min;
Serial.println("diffrential");
Serial.println(diff);
}
}
}
}
}