View Single Post
Old 04-15-2009, 06:34 PM   #9 (permalink)
dcb
needs more cowbell
 
dcb's Avatar
 
Join Date: Feb 2008
Location: ÿ
Posts: 5,038

pimp mobile - '81 suzuki gs 250 t
90 day: 96.29 mpg (US)

schnitzel - '01 Volkswagen Golf TDI
90 day: 53.56 mpg (US)
Thanks: 158
Thanked 269 Times in 212 Posts
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 0nbatx++){
    
pinMode(npins[x],OUTPUT);
    
pinMode(ppins[x],OUTPUT);
  }
}

int bat=0;
void loop(){
  
//turn off all pins
  
for(int x 0nbatx++){
    
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
    

__________________
WINDMILLS DO NOT WORK THAT WAY!!!

Last edited by dcb; 04-15-2009 at 06:45 PM..
  Reply With Quote