0% found this document useful (0 votes)
26 views2 pages

New

The document contains code to read analog values from a pin, find the minimum value, time intervals between readings, and output readings and timing data to serial. It initializes serial communication, sets pin modes, then loops to read analog pin A5, find minimum value, time intervals when minimum drops, and print readings and timing to serial.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

New

The document contains code to read analog values from a pin, find the minimum value, time intervals between readings, and output readings and timing data to serial. It initializes serial communication, sets pin modes, then loops to read analog pin A5, find minimum value, time intervals when minimum drops, and print readings and timing to serial.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

unsigned long time1;

unsigned long time2;


unsigned long time;
unsigned long time3;

int x;
int y;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);

// the loop routine runs over and over again forever:


void loop() {
x=1023;
y=1023;
// read the input on analog pin 0:

for ( int i = 0 ; i < 400 ; i++ ) {


int s = analogRead(A5);

if(s<x){x=s;}
// print out the value you read:
Serial.print(s);
Serial.print(" ");
Serial.println(x);
delay(1); }
////////////////
for ( int i = 0 ; i <10 ; i++ ) {
Serial.println("vvvvvv");
time = millis ( ) ;
time1= time;
}
for ( int i = 0 ; i < 400 ; i++ ) {
int s = analogRead(A5);
time = millis ( ) ;
if(s<y){y=s;}
if (y<x-50){time2=time; //digitalWrite (13,0) ;
time3=(time2-time1);
i=401;

}
// print out the value you read:
Serial.print(time3);
Serial.print(" ");
Serial.print(s);
Serial.print(" ");
Serial.print(x);

Serial.print(" ");
Serial.println(y);
delay(1); }
delay(5000);
/////////////

if (x==0){ // Serial.print("*y"+String(60/(time3/1000))+"*");
// Serial.println(60/(time3/1000));
tone ( 2 , 500, 100 ) ;
time1=time;
//digitalWrite (13,1) ;
}
if(x==0){
time2=time; //digitalWrite (13,0) ;
time3=(time2-time1); }

You might also like