Skip to main content

 I urgently need individuals who are willing to cooperate on my website and projects.

Extreme Programming with microcontrollers

Published: 27 September 2010
Last updated: 29 September 2018


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);
    { 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);