Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 19th, 2010 | Syntax: C | Size: 1.72 KB | Hits: 65 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. //Project to test the Delphi sensors
  2.  
  3. int analogPin = 0;     // potentiometer wiper (middle terminal) connected to analog pin 3
  4.                        // outside leads to ground and +5V
  5. int raw = 0;           // variable to store the raw input value
  6. float Vin = 4.38;           // variable to store the input voltage
  7. float Vout = 0;        // variable to store the output voltage
  8. float R1 = 10000;         // variable to store the R1 value
  9. float R2 = 0;          // variable to store the R2 value
  10. float buffer = 0;
  11.  
  12.  
  13. void setup()
  14. {
  15.    Serial.begin(9600);
  16.    
  17. }
  18. void loop() // run over and over again
  19. {
  20.   selectLineOne();
  21.  
  22.   raw = analogRead(analogPin);    // Reads the Input PIN
  23.   Vout = (5.0 / 1023.0) * raw;    // Calculates the Voltage on th Input PIN
  24.   buffer = (Vin / Vout) - 1;
  25.   R2 = R1 / buffer;
  26.   Serial.print("Voltage: ");      //
  27.   Serial.println(Vout);           // Outputs the information
  28.   selectLineTwo();
  29.   Serial.print("R2: ");           //
  30.   Serial.println(R2);
  31.   selectLineThree();
  32.   Serial.print(" Pin:");
  33.   Serial.print(analogRead(analogPin));
  34.   delay(1000);
  35.  
  36.  }
  37.  
  38.  //SerialLCD Functions
  39. void selectLineOne(){  //puts the cursor at line 0 char 0.
  40.    Serial.print(0xFE, BYTE);   //command flag
  41.    Serial.print(128, BYTE);    //position
  42. }
  43. void selectLineTwo(){  //puts the cursor at line 2 char 0.
  44.    Serial.print(0xFE, BYTE);   //command flag
  45.    Serial.print(192, BYTE);    //position
  46. }
  47. void selectLineThree(){  //puts the cursor at line 3 char 0.
  48.    Serial.print(0xFE, BYTE);   //command flag
  49.    Serial.print(148, BYTE);    //position
  50. }
  51. void selectLineFour(){  //puts the cursor at line 4 char 0.
  52.    Serial.print(0xFE, BYTE);   //command flag
  53.    Serial.print(212, BYTE);    //position
  54. }