Untitled
By: a guest | Mar 19th, 2010 | Syntax:
C | Size: 1.72 KB | Hits: 65 | Expires: Never
//Project to test the Delphi sensors
int analogPin = 0; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V
int raw = 0; // variable to store the raw input value
float Vin = 4.38; // variable to store the input voltage
float Vout = 0; // variable to store the output voltage
float R1 = 10000; // variable to store the R1 value
float R2 = 0; // variable to store the R2 value
float buffer = 0;
void setup()
{
Serial.begin(9600);
}
void loop() // run over and over again
{
selectLineOne();
raw = analogRead(analogPin); // Reads the Input PIN
Vout = (5.0 / 1023.0) * raw; // Calculates the Voltage on th Input PIN
buffer = (Vin / Vout) - 1;
R2 = R1 / buffer;
Serial.print("Voltage: "); //
Serial.println(Vout); // Outputs the information
selectLineTwo();
Serial.print("R2: "); //
Serial.println(R2);
selectLineThree();
Serial.print(" Pin:");
Serial.print(analogRead(analogPin));
delay(1000);
}
//SerialLCD Functions
void selectLineOne(){ //puts the cursor at line 0 char 0.
Serial.print(0xFE, BYTE); //command flag
Serial.print(128, BYTE); //position
}
void selectLineTwo(){ //puts the cursor at line 2 char 0.
Serial.print(0xFE, BYTE); //command flag
Serial.print(192, BYTE); //position
}
void selectLineThree(){ //puts the cursor at line 3 char 0.
Serial.print(0xFE, BYTE); //command flag
Serial.print(148, BYTE); //position
}
void selectLineFour(){ //puts the cursor at line 4 char 0.
Serial.print(0xFE, BYTE); //command flag
Serial.print(212, BYTE); //position
}