whats wrong with this statement

#include <LiquidCrystal.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int injectorpin = 9;
const int sensorPin = A0;
int duty=0 ;
  //           0  1  2  3   4   5  6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21 22  23   24  25 psi 
int value[] = {0, 0, 0, 0, 20, 20, 20, 20, 20, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 27, 28, 29, 29, 29, };    



void setup() {

  //---------------------------------------------- Set PWM frequency for D5 & D6 -------------------------------

  //TCCR0B = TCCR0B & B11111000 | B00000001;    // set timer 0 divisor to     1 for PWM frequency of 62500.00 Hz
  //TCCR0B = TCCR0B & B11111000 | B00000010;    // set timer 0 divisor to     8 for PWM frequency of  7812.50 Hz
  //TCCR0B = TCCR0B & B11111000 | B00000011;    // set timer 0 divisor to    64 for PWM frequency of   976.56 Hz (The DEFAULT)
  //TCCR0B = TCCR0B & B11111000 | B00000100;    // set timer 0 divisor to   256 for PWM frequency of   244.14 Hz
  TCCR0B = TCCR0B & B11111000 | B00000101;    // set timer 0 divisor to  1024 for PWM frequency of    61.04 Hz


  //---------------------------------------------- Set PWM frequency for D9 & D10 ------------------------------

  //TCCR1B = TCCR1B & B11111000 | B00000001;    // set timer 1 divisor to     1 for PWM frequency of 31372.55 Hz
  //TCCR1B = TCCR1B & B11111000 | B00000010;    // set timer 1 divisor to     8 for PWM frequency of  3921.16 Hz
  //TCCR1B = TCCR1B & B11111000 | B00000011;    // set timer 1 divisor to    64 for PWM frequency of   490.20 Hz (The DEFAULT)
  TCCR1B = TCCR1B & B11111000 | B00000100;    // set timer 1 divisor to   256 for PWM frequency of   122.55 Hz
  //TCCR1B = TCCR1B & B11111000 | B00000101;    // set timer 1 divisor to  1024 for PWM frequency of    30.64 Hz

  //---------------------------------------------- Set PWM frequency for D3 & D11 ------------------------------

  //TCCR2B = TCCR2B & B11111000 | B00000001;    // set timer 2 divisor to     1 for PWM frequency of 31372.55 Hz
  //TCCR2B = TCCR2B & B11111000 | B00000010;    // set timer 2 divisor to     8 for PWM frequency of  3921.16 Hz
  //TCCR2B = TCCR2B & B11111000 | B00000011;    // set timer 2 divisor to    32 for PWM frequency of   980.39 Hz
  TCCR2B = TCCR2B & B11111000 | B00000100;    // set timer 2 divisor to    64 for PWM frequency of   490.20 Hz (The DEFAULT)
  //TCCR2B = TCCR2B & B11111000 | B00000101;    // set timer 2 divisor to   128 for PWM frequency of   245.10 Hz
  //TCCR2B = TCCR2B & B11111000 | B00000110;    // set timer 2 divisor to   256 for PWM frequency of   122.55 Hz
  //TCCR2B = TCCR2B & B11111000 | B00000111;    // set timer 2 divisor to  1024 for PWM frequency of    30.64 Hz

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("water/meth ");
  lcd.setCursor(4, 1);
  lcd.print("injection ");
  delay(200);
  lcd.clear(); 
  lcd.setCursor(2, 1);
  lcd.print("% Spray");

  pinMode(injectorpin, OUTPUT); // output pin 6
  Serial.begin(9600);
}
void loop() {
  delay(20);
  int bst = analogRead(A0);



  float bstinput = bst * (5.0 / 1024.0);
  float bstinput2 = bstinput * 0.5376;                                                                            //int bstinput = ((bst*0.004887)*0.5376); // "1023/5= 0.004887"x"analogread 0-1023"=voltage  voltage*0.5376= boost in absolute bar  
  float bstinput3 = bstinput2-1.000; // (boostabs-outside)x"bar to psi "
  float bstinput1= bstinput3*14.5038;

if(bstinput1 < 0) // setting hg to psi at -
  {
int duty= 0;   
  }
  {
   int i = round(bstinput1); //selecting array 
   int duty=(value[i]); 
  }

why wont this work ? why does duty stay at zero even with bstinput1 larger than zero ?

Let's start with saying your not posting a statement. You post a program with some heavy port manipulation...

grizzle245:
why does duty stay at zero even with bstinput1 larger than zero ?

And what makes you think that?

Too many things called "duty"?

You should not declare duty again in the sketch. This way you make new local variable which is destroyed at end of the if statement.
Try Google local vs. global variables, you NEED to understand it.

   int i = round(bstinput1); //selecting array 
   int duty=(value[i]); 
   if(bstinput1 < 0) int duty=00;

got a different method here, works now

but would like the array method to work, it starts to read past zero hence the statement

Smajdalf:
You should not declare duty again in the sketch. This way you make new local variable which is destroyed at end of the if statement.
Try Google local vs. global variables, you NEED to understand it.

if this was correct regarding if(bstinput1 < 0) int duty=00; then the other program would not run

Hi,
What voltage have you got feeding Vin?
You Autodesk model shows 5V, that will not be enough for the Arduino onboard linear reg to output 5V.

Tom.. :slight_smile:

hi tom

in reality im going to run it with a 12v to 9v regulator