Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #include <Servo.h>
  4. Servo myservo;
  5. int val;
  6. int summe;
  7. int Anzeige;
  8. #define WRITE 2
  9. #define READ 3
  10. #define WREN 6
  11. #include <OneWire.h>
  12. #include <SPI.h>
  13. OneWire ds(8);
  14. unsigned int data;
  15. unsigned int address;
  16. // Data wire is plugged into port 2 on the Arduino
  17. #define ONE_WIRE_BUS 9// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  18. OneWire oneWire(ONE_WIRE_BUS);
  19. // Pass our oneWire reference to Dallas Temperature.
  20. DallasTemperature sensors(&oneWire);
  21. void setup(void)
  22. {
  23. myservo.attach(5);
  24. // start serial port
  25. Serial.begin(9600);
  26. }
  27. void loop(void)
  28. {
  29. summe=0;
  30. int numberOfDevices; // Number of temperature devices found
  31. DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
  32.  
  33. sensors.begin();
  34. // Grab a count of devices on the wire
  35. numberOfDevices = sensors.getDeviceCount();
  36. Serial.print("Parasit:");
  37. if (sensors.isParasitePowerMode()) Serial.print("ON ");
  38. else Serial.print("OFF ");
  39.  
  40. Serial.print(" Anzahl:");
  41. Serial.print(numberOfDevices, DEC);
  42. // report parasite power requirements
  43. sensors.requestTemperatures(); // Send the command to get temperatures
  44.  
  45. // Loop through each device, print out temperature data
  46. for(int i=0;i<numberOfDevices; i++)
  47. {
  48. // Search the wire for address
  49. if(sensors.getAddress(tempDeviceAddress, i))
  50. {
  51. // Output the device ID
  52. Serial.print(" Sensor");
  53. Serial.print(i+1,DEC);
  54. Serial.print(" =");
  55.  
  56. float tempC = sensors.getTempC(tempDeviceAddress);
  57. Serial.print(tempC);
  58. Serial.print(" Grad Celsius");
  59. {
  60. SPI.setBitOrder(MSBFIRST);
  61. SPI.setDataMode(SPI_MODE0);
  62. SPI.begin();
  63.  
  64. digitalWrite(SS, LOW);
  65. SPI.transfer(WRITE); // write instruction
  66. SPI.transfer((address >> 16) & 255);
  67. SPI.transfer((address >> 8) & 255);
  68. SPI.transfer(address & 255);
  69. SPI.transfer(tempC);
  70. digitalWrite(SS, HIGH);
  71.  
  72. delay(1000);
  73.  
  74. digitalWrite(SS, LOW);
  75. SPI.transfer(READ); // read instruction
  76. SPI.transfer((address >> 16) & 255);
  77. SPI.transfer((address >> 8) & 255);
  78. SPI.transfer(address & 255); // 3rd byte of address
  79. tempC = SPI.transfer(0); // Clock out the data
  80. Serial.print("Read Data = ");
  81. Serial.print((float)tempC,DEC);
  82. digitalWrite(SS, HIGH);
  83. delay(1000);
  84.  
  85.  
  86. {
  87.  
  88. summe=((summe+=tempC)/i);
  89. Anzeige= summe+1;
  90. }
  91.  
  92.  
  93.  
  94.  
  95. }
  96.  
  97.  
  98.  
  99. }
  100.  
  101.  
  102. }
  103. val= Anzeige;
  104.  
  105. val= map(val, 24, 26, 0, 180);
  106. myservo.write(val);
  107. delay(15);
  108.  
  109. Serial.print(Anzeige);
  110.  
  111. Serial.println("");
  112.  
  113. delay(1000);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement