Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include <Servo.h>
- Servo myservo;
- int val;
- int summe;
- int Anzeige;
- #define WRITE 2
- #define READ 3
- #define WREN 6
- #include <OneWire.h>
- #include <SPI.h>
- OneWire ds(8);
- unsigned int data;
- unsigned int address;
- // Data wire is plugged into port 2 on the Arduino
- #define ONE_WIRE_BUS 9// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
- OneWire oneWire(ONE_WIRE_BUS);
- // Pass our oneWire reference to Dallas Temperature.
- DallasTemperature sensors(&oneWire);
- void setup(void)
- {
- myservo.attach(5);
- // start serial port
- Serial.begin(9600);
- }
- void loop(void)
- {
- summe=0;
- int numberOfDevices; // Number of temperature devices found
- DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
- sensors.begin();
- // Grab a count of devices on the wire
- numberOfDevices = sensors.getDeviceCount();
- Serial.print("Parasit:");
- if (sensors.isParasitePowerMode()) Serial.print("ON ");
- else Serial.print("OFF ");
- Serial.print(" Anzahl:");
- Serial.print(numberOfDevices, DEC);
- // report parasite power requirements
- sensors.requestTemperatures(); // Send the command to get temperatures
- // Loop through each device, print out temperature data
- for(int i=0;i<numberOfDevices; i++)
- {
- // Search the wire for address
- if(sensors.getAddress(tempDeviceAddress, i))
- {
- // Output the device ID
- Serial.print(" Sensor");
- Serial.print(i+1,DEC);
- Serial.print(" =");
- float tempC = sensors.getTempC(tempDeviceAddress);
- Serial.print(tempC);
- Serial.print(" Grad Celsius");
- {
- SPI.setBitOrder(MSBFIRST);
- SPI.setDataMode(SPI_MODE0);
- SPI.begin();
- digitalWrite(SS, LOW);
- SPI.transfer(WRITE); // write instruction
- SPI.transfer((address >> 16) & 255);
- SPI.transfer((address >> 8) & 255);
- SPI.transfer(address & 255);
- SPI.transfer(tempC);
- digitalWrite(SS, HIGH);
- delay(1000);
- digitalWrite(SS, LOW);
- SPI.transfer(READ); // read instruction
- SPI.transfer((address >> 16) & 255);
- SPI.transfer((address >> 8) & 255);
- SPI.transfer(address & 255); // 3rd byte of address
- tempC = SPI.transfer(0); // Clock out the data
- Serial.print("Read Data = ");
- Serial.print((float)tempC,DEC);
- digitalWrite(SS, HIGH);
- delay(1000);
- {
- summe=((summe+=tempC)/i);
- Anzeige= summe+1;
- }
- }
- }
- }
- val= Anzeige;
- val= map(val, 24, 26, 0, 180);
- myservo.write(val);
- delay(15);
- Serial.print(Anzeige);
- Serial.println("");
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement