Advertisement
wariat

Untitled

May 27th, 2013
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. float mAh = 0;
  2. int   time_m = 0;
  3.  
  4. void setup()
  5. {
  6.   Serial.begin( 9600 );
  7.  
  8.   for ( int i = 10; i > 0; i-- )
  9.   {
  10.     Serial.print ( i );
  11.     delay ( 1000 );
  12.   }
  13.   Serial.println( "GO!" );
  14. }
  15.  
  16. void loop(  ) {
  17.  
  18.   float average = 0;
  19.   for( int i = 0; i < 1000; i++ ) // 1000 samples
  20.   {
  21.     float sample = ( 26.4 * analogRead( A0 ) - 13510 ) / 1000;
  22.     if ( sample > 0 )
  23.     {
  24.       average += sample;
  25.     }
  26.     delay( 60 ); // every 60 ms
  27.   }
  28.  
  29.   mAh += average / 60;
  30.   time_m++;
  31.  
  32.   Serial.print  ( time_m );  
  33.   Serial.print  ( ", min, " );
  34.   Serial.print  ( average );  
  35.   Serial.print  ( ", mA, " );  
  36.   Serial.print  ( mAh );  
  37.   Serial.println( ", mAh" );
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement