Go Down

### Topic: horse power calculator (Read 1 time)previous topic - next topic

#### LandonW

##### Mar 17, 2017, 10:34 pmLast Edit: Mar 21, 2017, 03:48 am by Coding Badly
Looking for help writing a code to calculate and display a horse power calculation. This is the formula I need to use

(analog1*200) * (analog2"*80) /700 =?    analog1 is 0-5 VDC... analog2 is mVdc.

The display does not match the math. its over double what it should be.

I used the example sketch for "hello world" to wire lcd

I built two variable voltage circuits to control the analog inputs.

Here's my code. Please help, I'm new to coding but not new to electrical/electronic theory/practice

Code: [Select]
`/*Trying to calculate horse power and display on lcd http://www.arduino.cc/en/Tutorial/LiquidCrystal */// include the library code:#include <LiquidCrystal.h>// initialize the library with the numbers of the interface pinsLiquidCrystal lcd(12, 11, 5, 4, 3, 2);   int  voltPin = A1;  int mvoltPin = A7;  int c = 200;  int d = 80;  int e = 700;  float voltValue = 0;  float mvoltValue = 0;  float sum = ((voltValue*c*mvoltValue*d)/e);void setup() {  // set up the LCD's number of columns and rows:  lcd.begin(16, 2);  // Print a message to the LCD.  lcd.print("Horse Power");}void loop(){  //(voltValue*c)*(mvoltValue*d)/e;   // set the cursor to column 0, line 1  // (note: line 1 is the second row, since counting begins with 0):  lcd.setCursor(0,1);  // horse power calculationvoltValue = analogRead (voltPin);mvoltValue = analogRead (mvoltPin);  lcd.print (voltValue*c)*(mvoltValue*d)/e;  delay(1700);return;}`

Moderator edit: [code] [/code] tags added.

#### GrooveFlotilla

#1
##### Mar 17, 2017, 10:38 pm
Code: [Select]
` lcd.print (voltValue*c)*(mvoltValue*d)/e;`The compiler didn't like that line, did it?
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

#### LandonW

#2
##### Mar 17, 2017, 11:03 pm
Actually it didn't give me any errors

#### jremington

#3
##### Mar 17, 2017, 11:08 pm
Then you posted the wrong program. Post the entire program, using code tags.

If you don't know what those are, read and follow the directions in the "How to use this forum" post.

#### GrooveFlotilla

#4
##### Mar 17, 2017, 11:10 pm
Actually it didn't give me any errors
I do believe you may be correct, but it still isn't semantically correct.
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

#### jremington

#5
##### Mar 17, 2017, 11:18 pmLast Edit: Mar 17, 2017, 11:18 pm by jremington
Quote
I do believe you may be correct, but it still isn't semantically correct.
Hmmm...

I don't have access to an Arduino to test, but perhaps this line:

Code: [Select]
`lcd.print (voltValue*c)*(mvoltValue*d)/e;`

is equivalent to multiplying the return value from lcd.print() by something, and ignoring the result:

Code: [Select]
`((mvoltValue*d)/e)*lcd.print (voltValue*c);`

#### GrooveFlotilla

#6
##### Mar 17, 2017, 11:21 pm
Hmmm...

I don't have access to an Arduino to test, but perhaps this line:

Code: [Select]
`lcd.print (voltValue*c)*(mvoltValue*d)/e;`

is equivalent to multiplying the return value from lcd.print() by something, and ignoring the result:

Code: [Select]
`((mvoltValue*d)/e)*lcd.print (voltValue*c);`
Yup...that's what I read second time I looked at it.
Syntax correct, flakey semantics.
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

#### LandonW

#7
##### Mar 17, 2017, 11:38 pm
I changed to the

((mvoltValue*d)/e)*lcd.print (voltValue*c);

still no change

#### GrooveFlotilla

#8
##### Mar 17, 2017, 11:39 pm
I changed to the

((mvoltValue*d)/e)*lcd.print (voltValue*c);

still no change

No surprise there.
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

#### Grumpy_Mike

#9
##### Mar 17, 2017, 11:43 pm
I changed to the

((mvoltValue*d)/e)*lcd.print (voltValue*c);

still no change

Funnest thing I have read all year.

You rearrange something that is wrong into something that is equivalent and are surprised that it is still wrong.

Now if you still don't understand it is wrong after all you have been told, then say what you don't understand about what you have been told.

#### LandonW

#10
##### Mar 18, 2017, 12:07 am
any clue on how to make it calculate correctly??

#### GrooveFlotilla

#11
##### Mar 18, 2017, 12:09 am
The calculation is probably correct, it's just that you're not calculating what you think you are.
Code: [Select]
`lcd.print ((voltValue*c)*(mvoltValue*d)/e);`
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

#### LandonW

#12
##### Mar 18, 2017, 12:12 am
I've tried writing that way too. still doesn't add up like it should or like it does when done on a calculator

#### GrooveFlotilla

#13
##### Mar 18, 2017, 12:17 am
Throw in some float casts and see how things develop
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

#### TomGeorge

#14
##### Mar 18, 2017, 08:11 am
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom..
Everything runs on smoke, let the smoke out, it stops running....

Go Up