I generally just leave people to it rather than write any code for them, but if you're pretty new to it all, then it can be daunting because often people open up the IDE and just stare at the blank screen.
Whilst I rarely do it these days, I almost always planned software for micros with a flow chart/diagram. You start off with very basic commands like 'read battery voltage', or 'if this button do this'. A diagram is, I think, a bit nicer than just text. Then start on pseudo-code, where you convert that program flow into very basic language - providing instructions that anyone can follow, being very specific about what needs to be done, so there is no ambiguity.
You then should go through each stage, and pad it out, either by translating it directly to code, or more likely, just more detailed pseudo-code. The arduino IDE gets you started with two simple routines: 'setup', and 'loop'. As you probably know, the 'setup' is run once at start-up - this is where you set IO's as inputs or outputs, set default values for variables, configure hardware peripherals etc..
The loop is as basic as it gets - it will run forever unless the MCU is reset, the power is turned off (obviously) or there are certain commands like 'break', which will leave the main loop, and start back on the setup routine.
I can't say I'm overly experienced in coding, but I almost always have at the very least - notepad - open making notes before and during writing the code. It helps to get idea's down and keep track of the main structure. For example, in your project I would write down 'things the MCU needs to do:
- turn on active load/constant current sink for any battery that is enabled.
- Measure each battery's voltage.
- Measure each ones current
- Check voltage is not < minimum.
- display voltages on LCD
perhaps not in any order, but at least these can be thought of as 'blocks' of code.
Then there's variables. How many do you need? what sorts of things do we need to store? Are they variable at all or constant throughout? As you have four batteries, it is likely that each battery will need a few variables, namely, voltage, current, discharge_time, perhaps even starting_voltage.
As they are the same variables for each battery, you could create a structure (
http://playground.arduino.cc/Code/Struct) that encompasses all the above. Or have each variable as an array, for example:
unsigned int BattVoltage[4] = {0,0,0,0};
Creates an array of 16-bit variables, with 4 members.
You can read/write to these by pointing to each one with BatteryVoltage[j] where 'j' is a number 0-3 (arrays first entry is at '0'). This way you can write just one routine for measuring voltage and current, converting them into mV, or mA but each time changing the variable 'i' to select a different battery. This is why loops are so useful - if the same thing(s) must be done multiple times, perhaps for multiple things, a for-loop can go through each iteration.
Similarly, you're writing a voltage to the LCD, the only variables being - print location (starting location, and line) and the number it prints. So you could have your voltages stored in global arrays/variables, and have a subroutine called whose only purpose is to read those values and print them on the LCD. It can be passed things that change such as LCD location, line, and voltage meaning you can just write a routine and call it with 'LCD_print_volts(<start_loc><line><value for voltage>)'.
There are so many 'ways' of doing these things, some more complicated than others, some more efficient. I learned simply by setting myself a task of writing code that did something useful, and writing out a rough plan of what it should do, and how it should do it, and then... most likely getting stuck very easily - googling for examples on how to do specific things. I believe people get stuck because they don't clearly define what it is they want to do, that is why writing pseudo-code is a good start, if you can break everything down into very simple terms, it makes it more specific, and so you can google 'reading voltages on arduino ADC' rather than 'how to arduino battery'. This way, you may have a lots of things you'll have to research to understand, but each one is quite simple. So instead of wasting time just sitting at a blank arduino project you have things 'to do'.
Apologies for the long disjointed rant. I have no idea if you've written code for anything before, so I assumed you hadn't. But this sort of project sounds
perfect for learning how. Its pretty linear/sequential, it has lots of inputs and outputs, it has a few variables to keep track of, and its 'modular' - you can easily break it down into smaller parts that you can work on one at a time, or even improve later. Anyone can copy/paste someone elses code,and sometimes using pre-written code is a good way to learn (providing you take the time to see exactly what each part is doing, why, and how) but sooner or later one should just start from scratch. There are libraries there to help you, and examples of how to use those libraries but ultimately if you want a micro to do exactly what you want - you have to tell it how
Editted: of course using [j] with an i
when not in code blocks makes everything after Italic - like a rant on a political blog...