hi everyone
i read the analog value from my sensor and see the data ,which is taken by every 1000 ms.
i want to write a code regarding to calculating the difference between every two values(sequential) then
will enter next step if the difference between two values is higher than 3 .
i couldnt imagine how i use "if statement" and how i show the difference between two sequential data on code.
my code:
const int peak = 3;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println("Is the sensor placed? ");
Serial.println("type y or n ");
Serial.println("CLEARDATA");
Serial.print("LABEL,Time,peak of current");
}
// the loop routine runs over and over again forever:
void loop() {
char Input = Serial.read();
// User selected yes
if(Input == 'y')
{
for(int i=1; i<=100 ; i=i+1)
{
// read the input on analog pin 0:
int sensorValue = analogRead(A1);
int row=0;
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5/1023.0);
float current = (1000*voltage)/46.7 ;
float ms = (current-3.9)*19.6/15.7 ;
// print out the value you read:
if (ms < peak ){// the difference between two ms values ?
Serial.print("DATA,TIME, ");
Serial.print(current);
row ++;
current ++;
i=0;
}
delay(1000);
}
}
}