Advertisement
Guest User

Untitled

a guest
May 31st, 2011
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. int msrin = 10;
  2. int refin = 11;
  3. int led = 13;
  4. int compout = 9;
  5. long microstart = 0;
  6. long microend = 0;
  7. int msrinput = 0;
  8. long calced1;
  9. float calced;
  10.  
  11. void setup() {
  12.  
  13.   Serial.begin(9600);
  14.   pinMode(msrin, OUTPUT);  
  15.   pinMode(refin, OUTPUT);  
  16.   pinMode(led, OUTPUT);    
  17.   pinMode(compout, INPUT);  
  18. }
  19.  
  20. void loop() {
  21.  
  22.   digitalWrite(msrin, HIGH);
  23.   digitalWrite(refin, LOW);
  24.   while (1)
  25.   {
  26.     msrinput = digitalRead(compout);
  27.     if (msrinput == 0)
  28.     {
  29.       microstart = micros();
  30.       break;
  31.     }
  32.   }
  33.  
  34.   while (1)
  35.   {
  36.     microend = micros();
  37.     if ((microend - microstart) >= 100000)
  38.     {
  39.       break;
  40.     }
  41.   }
  42.  
  43.   digitalWrite(msrin, LOW);
  44.   digitalWrite(refin, HIGH);
  45.   microstart = micros();
  46.  
  47.   while(1) //check if cap is uncharged
  48.   {
  49.     msrinput = digitalRead(compout);
  50.     if (msrinput == 1)
  51.     {
  52.       microend = micros();
  53.       calced1 = (microend - microstart);
  54.       calced = 2.52 * (calced1 / 100000.0);
  55.       Serial.println(calced);
  56.       break;
  57.     }
  58.   }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement