justhrun

maxval_dualsensor.ino

Sep 29th, 2014
232
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define SENSOR1PIN  A0 // terserah
  2. #define SENSOR2PIN  A1 // terserah
  3.  
  4. int analog1Val = 0;
  5. int analog2Val = 0;
  6. int max1Val = 0;
  7. int max2Val = 0;
  8. int tmpVal = 0;
  9. unsigned long tStart = 0;
  10.  
  11. void setup() {
  12.   Serial.begin(9600);
  13. }
  14.  
  15. void loop() {
  16.   max1Val = 0;
  17.   max2Val = 0;
  18.   tStart = millis();
  19.   while(millis()-tStart < 60000) {  // 1menit
  20.     analog1Val = 0;
  21.     analog2Val = 0;
  22.     for(int i=0;i<5;i++) {
  23.       analog1Val += analogRead(SENSOR1PIN);
  24.       analog2Val += analogRead(SENSOR2PIN);
  25.       delay(7);
  26.     } // ngabisin waktu +/- 35ms
  27.     tmpVal = (int) analog1Val/5;
  28.     if(tmpVal > max1Val) {
  29.       max1Val = tmpVal;
  30.     }
  31.     tmpVal = (int) analog2Val/5;
  32.     if(tmpVal > max2Val) {
  33.       max2Val = tmpVal;
  34.     }
  35.     delay(9960);  // diem 10detik
  36.   }
  37.   Serial.print("Sensor1 Max = " );
  38.   Serial.print(max1Val,DEC);
  39.   Serial.print(" / Sensor2 Max = " );
  40.   Serial.println(max2Val,DEC);
  41. }
RAW Paste Data