Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.01 KB | None | 0 0
  1. // Data wire is plugged into port 2 on the Arduino
  2. #define SHORT_TEMP_FIRST_SENSOR 0
  3. #define SHORT_TEMP_SECOND_SENSOR 1
  4. #define LONG_TEMP_SENSOR 2
  5. #define OUTSIDE_TEMP_SENSOR 3
  6.  
  7. int shortFirstSensorInput;
  8. int shortSensorInput;
  9. int longSensorInput;
  10. int outsideSensorInput;
  11.  
  12. double tempFirstShot;
  13. double tempShort;
  14. double tempLong;
  15. double tempOutside;
  16.  
  17. double tempFirstShotResult;
  18. double tempShortResult;
  19. double tempLongResult;
  20. double tempOutsideResult;
  21.  
  22. int cycleCounter;
  23. int outCounter;
  24.  
  25. /*
  26.  * The setup function. We only start the sensors here
  27.  */
  28. void setup(void)
  29. {
  30.   // start serial port
  31.   Serial.begin(9600);
  32. }
  33.  
  34. /*
  35.  * Main function, get and show the temperature
  36.  */
  37. void loop(void)
  38. {
  39.  
  40.   shortFirstSensorInput = analogRead(SHORT_TEMP_FIRST_SENSOR);  
  41.   shortSensorInput = analogRead(SHORT_TEMP_SECOND_SENSOR);  
  42.   longSensorInput = analogRead(LONG_TEMP_SENSOR);  
  43.   outsideSensorInput = analogRead(OUTSIDE_TEMP_SENSOR);  
  44.  
  45.   tempFirstShot = (double)shortFirstSensorInput / 1024;   //find percentage of input reading
  46.   tempFirstShot = tempFirstShot * 5;                     //multiply by 5V to get voltage
  47.   tempFirstShot = tempFirstShot - 0.5;                   //Subtract the offset
  48.   tempFirstShot = tempFirstShot * 100;                   //Convert to degrees
  49.  
  50.   tempShort = (double)shortSensorInput / 1024;   //find percentage of input reading
  51.   tempShort = tempShort * 5;                     //multiply by 5V to get voltage
  52.   tempShort = tempShort - 0.5;                   //Subtract the offset
  53.   tempShort = tempShort * 100;                   //Convert to degrees
  54.  
  55.   tempLong = (double)longSensorInput / 1024;   //find percentage of input reading
  56.   tempLong = tempLong * 5;                     //multiply by 5V to get voltage
  57.   tempLong = tempLong - 0.5;                   //Subtract the offset
  58.   tempLong = tempLong * 100;  
  59.  
  60.   tempOutside = (double)outsideSensorInput / 1024;   //find percentage of input reading
  61.   tempOutside = tempOutside * 5;                     //multiply by 5V to get voltage
  62.   tempOutside = tempOutside - 0.5;                   //Subtract the offset
  63.   tempOutside = tempOutside * 100;
  64.  
  65.   tempFirstShotResult+= tempFirstShot;
  66.   tempShortResult+= tempShort;
  67.   tempLongResult+= tempLong;
  68.   tempOutsideResult+= tempOutside;
  69.  
  70.   cycleCounter++;
  71.  
  72.   if (cycleCounter == 30)
  73.   {
  74.       outCounter++;
  75.  
  76.       Serial.print(outCounter);
  77.       Serial.print(" ");
  78.      
  79.       //Serial.print("OBR_TEMP = ");
  80.       Serial.print(tempFirstShotResult / 30);
  81.       Serial.print(" ");
  82.    
  83.       //Serial.print("POD_TEMP = ");
  84.       Serial.print(tempShortResult / 30);
  85.       Serial.print(" ");
  86.    
  87.       //Serial.print("HSE_TEMP = ");
  88.       Serial.print(tempLongResult / 30);
  89.       Serial.print(" ");
  90.    
  91.       //Serial.print("OUT_TEMP = ");
  92.       Serial.println(tempOutsideResult / 30);  
  93.  
  94.       cycleCounter = 0;
  95.       tempFirstShotResult = 0;
  96.       tempShortResult = 0;
  97.       tempLongResult = 0;
  98.       tempOutsideResult = 0;
  99.   }
  100.  
  101.   delay(1000);      
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement