Here is some arduino code that compiles that should convey the functionality of the above circuit (post 7):
PHP Code:
//haven't done my mosfet homework so making these defines
//pin value for turning on a p channel mosfet
#define pcon HIGH
//pin value for turning off a p channel mosfet
#define pcoff LOW
//pin value for turning on a n channel mosfet
#define ncon HIGH
//pin value for turning off a n channel mosfet
#define ncoff LOW
//number of batteries
#define nbat 4
//milliseconds to wait between switching batteries
#define pause 60000
//define the control pins
#define a 2
#define aa 3
#define b 4
#define bb 5
#define c 6
#define cc 7
#define d 8
#define dd 9
//put the pins in arrays for smaller program
int npins [] = {a,b,c,d};
int ppins [] = {aa,bb,cc,dd};
void setup(){
for(int x = 0; x < nbat; x++){
pinMode(npins[x],OUTPUT);
pinMode(ppins[x],OUTPUT);
}
}
int bat=0;
void loop(){
//turn off all pins
for(int x = 0; x < nbat; x++){
digitalWrite(npins[x],ncoff);
digitalWrite(ppins[x],pcoff);
}
//turn on the battery to charge
digitalWrite(npins[bat],ncon);
digitalWrite(ppins[bat],pcon);
delay(pause);
bat=(bat+1) % nbat; //point to the next battery modulo
}