Intro

I use the Extreme Programming (XP) / Agile software development methodology. One of its advantages is that by using understandable memberfuctions and variables, only few comments are required. The code is readable from itself. Another aspect is that classes and memberfunctions should be independent testable. We can even use Extreme Programming at the Arduino microcontroller. Because we use inline functions, no additional machine code will be generated.

Here is a c++ codefragment of my Solar cell curvetracer:

int CurveTracer::trace(bool printCurve, int _averaging, int stepTime_ms)
{ const int mVstep=5;
  averaging = _averaging;
  int Wire_mOhm = 2;
  int mV=0, mA=0, mW=0, mWpeak=0, mVnext=0;
  if(printCurve) Serial << F("\n\nmV mA mW ");

  for(int i=0; i<=1023; i++)
  { measure(i, stepTime_ms, mV, mA);   
    correctForWire(Wire_mOhm, mV, mA);
    if(i==0)
    { mAoffsetError = mA; // I should be 0 at start but isn't
      mVstart = mV;
      mVnext = mV;
    }   
    repairOffsetError(mV, mA);
    calcPower(mV, mA, mW, mWpeak);
   
    if(mV <= mVnext) // measurement direction 80 75 70mV
    { if(printCurve) dataOut(mV, mA, mW);
      //testOut(i, mVnext); // only for test    
      mVnext = mV - mVstep;
    }
  }
  Serial << F("\nmWpeak: ") << mWpeak;
  delay(1000); // pause time to read from screen
  return mWpeak;
}

The software is split down in many memberfunctions, as you can see. Altough some memberfunctions are very short, they are still written as memberfunctions. Look at the function calcPower:

void inline CurveTracer::calcPower(int mV, int mA, int &mW, int &mWpeak)
{ mW = (float)mA * mV / 1000;
  if(mW > mWpeak) mWpeak = mW;     
}

Here is the function call. It is not necessary to use comments because the code explains itself:

calcPower(mV, mA, mW, mWpeak);

Do you have any comments about the website or problems with shopping? Please let me know.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.