View Single Post
Old 12-31-2013, 01:37 PM   #11 (permalink)
P-hack
Master EcoModder
 
P-hack's Avatar
 
Join Date: Oct 2012
Location: USA
Posts: 1,408

awesomer - '04 Toyota prius
Thanks: 102
Thanked 252 Times in 204 Posts
just for fun here is my attempt at a working program, no ownership implied
Code:
int val = 0; 
unsigned long time;
boolean overboost;
void setup(){
  pinMode(0, OUTPUT);//don't need to set pin 3 for analogRead
}
void loop() {
  overboost=false;
  val=analogRead(3);  //
  //val should be between 204 and 716, 1v and 3.5v
  val=val-204;//  val between 0 and 512 
  if(val<0) val=0;
  if(val>510){
    val=510;
    overboost=true;
  }
  val=val/10; //val between 0 and 51, just right for 1v pwm
  if(overboost){
    time=millis()%500;
    if(time<250){
      val=0; //turn off pwm for 250ms out of 500ms 
             //  so the display flashes indicating overboost condition
    }  
  }
  analogWrite(0,val);
}
Binary sketch size: 1,460 bytes


Last edited by P-hack; 12-31-2013 at 07:04 PM..
  Reply With Quote