/ Freq_Meter
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Ammeter_Code.cpp Source File

Ammeter_Code.cpp

00001 /*
00002 the ammeter reads the voltage accross the shunt resister that is a set value
00003 this is used to calculate the current in the circuit
00004 a value for current will be printed in mA on the LCD screen
00005 
00006 */
00007 
00008 
00009 //Case x:
00010 lcd.locate(0.0)
00011 lcd.printf("Current: "); 
00012 
00013 
00014 AnalogIn vo(A5);  //reads the voltage across rshunt
00015 
00016 double vout= (3.3*vo)/4095; //converts from bits in the analog read
00017 double rshunt = 0.01;       //set value for rshunt
00018 int i;                      // declares a integer for i
00019 
00020 
00021 i = vout/rshunt;           // equation to find i
00022 
00023 if i<= 0.5{ 
00024 
00025 ifinal= i*1000; //converts into amps to mA
00026 lcd.locate(0,1);
00027 lcd.printf(".3f mA", ifinal);
00028     }
00029 else {
00030 lcd.locate(0,1);
00031 lcd.printf("out of range");
00032 }
00033 //if and else staments here are based in if the i that has been found is within the parameters 
00034   
00035