Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Ammeter_Code.cpp@3:b6e887e4ac75, 2020-04-01 (annotated)
- Committer:
- thomasosullivan
- Date:
- Wed Apr 01 20:58:55 2020 +0000
- Revision:
- 3:b6e887e4ac75
- Parent:
- 0:7f4ed364f7ea
Final ammeter
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| thomasosullivan | 3:b6e887e4ac75 | 1 | /* |
| thomasosullivan | 3:b6e887e4ac75 | 2 | the ammeter reads the voltage accross the shunt resister that is a set value |
| thomasosullivan | 3:b6e887e4ac75 | 3 | this is used to calculate the current in the circuit |
| thomasosullivan | 3:b6e887e4ac75 | 4 | a value for current will be printed in mA on the LCD screen |
| thomasosullivan | 3:b6e887e4ac75 | 5 | |
| thomasosullivan | 3:b6e887e4ac75 | 6 | */ |
| thomasosullivan | 3:b6e887e4ac75 | 7 | |
| thomasosullivan | 3:b6e887e4ac75 | 8 | |
| decland17 | 0:7f4ed364f7ea | 9 | //Case x: |
| thomasosullivan | 3:b6e887e4ac75 | 10 | lcd.locate(0.0) |
| thomasosullivan | 3:b6e887e4ac75 | 11 | lcd.printf("Current: "); |
| thomasosullivan | 3:b6e887e4ac75 | 12 | |
| thomasosullivan | 3:b6e887e4ac75 | 13 | |
| thomasosullivan | 3:b6e887e4ac75 | 14 | AnalogIn vo(A5); //reads the voltage across rshunt |
| decland17 | 0:7f4ed364f7ea | 15 | |
| thomasosullivan | 3:b6e887e4ac75 | 16 | double vout= (3.3*vo)/4095; //converts from bits in the analog read |
| thomasosullivan | 3:b6e887e4ac75 | 17 | double rshunt = 0.01; //set value for rshunt |
| thomasosullivan | 3:b6e887e4ac75 | 18 | int i; // declares a integer for i |
| thomasosullivan | 3:b6e887e4ac75 | 19 | |
| thomasosullivan | 3:b6e887e4ac75 | 20 | |
| thomasosullivan | 3:b6e887e4ac75 | 21 | i = vout/rshunt; // equation to find i |
| thomasosullivan | 3:b6e887e4ac75 | 22 | |
| thomasosullivan | 3:b6e887e4ac75 | 23 | if i<= 0.5{ |
| thomasosullivan | 3:b6e887e4ac75 | 24 | |
| thomasosullivan | 3:b6e887e4ac75 | 25 | ifinal= i*1000; //converts into amps to mA |
| thomasosullivan | 3:b6e887e4ac75 | 26 | lcd.locate(0,1); |
| thomasosullivan | 3:b6e887e4ac75 | 27 | lcd.printf(".3f mA", ifinal); |
| thomasosullivan | 3:b6e887e4ac75 | 28 | } |
| thomasosullivan | 3:b6e887e4ac75 | 29 | else { |
| thomasosullivan | 3:b6e887e4ac75 | 30 | lcd.locate(0,1); |
| thomasosullivan | 3:b6e887e4ac75 | 31 | lcd.printf("out of range"); |
| thomasosullivan | 3:b6e887e4ac75 | 32 | } |
| thomasosullivan | 3:b6e887e4ac75 | 33 | //if and else staments here are based in if the i that has been found is within the parameters |
| thomasosullivan | 3:b6e887e4ac75 | 34 | |
| thomasosullivan | 3:b6e887e4ac75 | 35 |