Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- /*
- DS18B20 Pinout (Left to Right, pins down, flat side toward you)
- - Left = Ground
- - Center = Signal (Pin 2): (with 3.3K to 4.7K resistor to +5 or 3.3 )
- - Right = +5 or +3.3 V
- /*-----( Import needed libraries )-----*/
- // Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
- #include <OneWire.h>
- //Get DallasTemperature Library here: http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
- #include <DallasTemperature.h>
- #include <util/delay.h>
- #include <avr/io.h>
- /*-----( Declare Constants and Pin Numbers )-----*/
- #define ONE_WIRE_BUS_PIN 0
- #define F_CPU 8000000 // This is used by delay.h library
- /*-----( Declare objects )-----*/
- // Setup a oneWire instance to communicate with any OneWire devices
- OneWire oneWire(ONE_WIRE_BUS_PIN);
- // Pass our oneWire reference to Dallas Temperature.
- DallasTemperature sensors(&oneWire);
- /*-----( Declare Variables )-----*/
- // Assign the addresses of your 1-Wire temp sensors.
- // See the tutorial on how to obtain these addresses:
- // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
- DeviceAddress Probe01 = { 0x28, 0xFF, 0x57, 0xED, 0xB5, 0x16, 0x03, 0x75 };
- DeviceAddress Probe02 = { 0x28, 0xFF, 0x4D, 0x93, 0xC1, 0x16, 0x04, 0xFB };
- void setup() /****** SETUP: RUNS ONCE ******/
- {
- /*
- Control Register A for Timer/Counter-0 (Timer/Counter-0 is configured using two registers: A and B)
- TCCR0A is 8 bits: [COM0A1:COM0A0:COM0B1:COM0B0:unused:unused:WGM01:WGM00]
- 2<<COM0A0: sets bits COM0A0 and COM0A1, which (in Fast PWM mode) clears OC0A on compare-match, and sets OC0A at BOTTOM
- 2<<COM0B0: sets bits COM0B0 and COM0B1, which (in Fast PWM mode) clears OC0B on compare-match, and sets OC0B at BOTTOM
- 3<<WGM00: sets bits WGM00 and WGM01, which (when combined with WGM02 from TCCR0B below) enables Fast PWM mode
- */
- // TCCR0A = 2<<COM0A0 | 2<<COM0B0 | 3<<WGM00;
- /*
- Control Register B for Timer/Counter-0 (Timer/Counter-0 is configured using two registers: A and B)
- TCCR0B is 8 bits: [FOC0A:FOC0B:unused:unused:WGM02:CS02:CS01:CS00]
- 0<<WGM02: bit WGM02 remains clear, which (when combined with WGM00 and WGM01 from TCCR0A above) enables Fast PWM mode
- 1<<CS00: sets bits CS01 (leaving CS01 and CS02 clear), which tells Timer/Counter-0 to not use a prescalar
- */
- // TCCR0B = 0<<WGM02 | 1<<CS00;
- /*
- Control Register for Timer/Counter-1 (Timer/Counter-1 is configured with just one register: this one)
- TCCR1 is 8 bits: [CTC1:PWM1A:COM1A1:COM1A0:CS13:CS12:CS11:CS10]
- 0<<PWM1A: bit PWM1A remains clear, which prevents Timer/Counter-1 from using pin OC1A (which is shared with OC0B)
- 0<<COM1A0: bits COM1A0 and COM1A1 remain clear, which also prevents Timer/Counter-1 from using pin OC1A (see PWM1A above)
- 1<<CS10: sets bit CS11 which tells Timer/Counter-1 to not use a prescalar
- */
- // TCCR1 = 0<<PWM1A | 0<<COM1A0 | 1<<CS10;
- /*
- General Control Register for Timer/Counter-1 (this is for Timer/Counter-1 and is a poorly named register)
- GTCCR is 8 bits: [TSM:PWM1B:COM1B1:COM1B0:FOC1B:FOC1A:PSR1:PSR0]
- 1<<PWM1B: sets bit PWM1B which enables the use of OC1B (since we disabled using OC1A in TCCR1)
- 2<<COM1B0: sets bit COM1B1 and leaves COM1B0 clear, which (when in PWM mode) clears OC1B on compare-match, and sets at BOTTOM
- */
- // GTCCR = 1<<PWM1B | 2<<COM1B0;
- /////////////////////////////////////////////////////////////////////////////////////////
- /*
- // start serial port to show results
- Serial.begin(9600);
- Serial.print("Initializing Temperature Control Library Version ");
- Serial.println(DALLASTEMPLIBVERSION);
- */
- ///////////////////////////////////////////////////////////////////////////////////////
- // Initialize the Temperature measurement library
- sensors.begin();
- // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
- sensors.setResolution(Probe01, 10);
- sensors.setResolution(Probe02, 10);
- //TCCR1B = TCCR1B & 0b11111000 | 0x05; //set divider for the 328
- TCCR0B = TCCR0B & 0b11111000 | 0b001 ; // set to divide-by-1 prescale ATTiny
- }//--(end setup )---
- void loop() /****** LOOP: RUNS CONSTANTLY ******/
- {
- // delay(5000); // This delay will no longer work with new clock settings
- _delay_ms(30000); // So we use this one
- ////////////////////////////////////////////////////////////////////////////////////
- /*
- Serial.println();
- Serial.print("Number of Devices found on bus = ");
- Serial.println(sensors.getDeviceCount());
- Serial.print("Getting temperatures... ");
- Serial.println();
- */
- ////////////////////////////////////////////////////////////////////////////////////
- // Command all devices on bus to read temperature
- sensors.requestTemperatures();
- //Serial.print("Probe 01 temperature is: ");
- printTemperature(Probe01);
- //Serial.println();
- }//--(end main loop )---
- /*-----( Declare User-written Functions )-----*/
- void printTemperature(DeviceAddress temps)
- {
- float tempOut = sensors.getTempC(Probe01);
- float tempIn = sensors.getTempC(Probe02);
- {
- /*
- if (tempIn == -127.00)
- {
- Serial.print("Error getting temperature ");
- }
- else
- {
- Serial.print("TI: ");
- Serial.print(tempIn);
- Serial.println();
- Serial.print("TO: ");
- Serial.print(tempOut);
- }
- */
- if (tempIn > tempOut +1.5 && tempIn <= tempOut + 4)
- {
- analogWrite(1, 155); //Attiny85 pin 1 // 328 pin 10
- analogWrite (2, 255); //Attiny85 pin 3 // 328 pin 5 Green
- analogWrite (3, 0); //Attiny85 pin 3 // 328 pin 5 Red
- analogWrite (4, 0); //Attiny85 pin 3 // 328 pin 5 Yellow
- }
- else if (tempIn > tempOut + 4 && tempIn <= tempOut +6)
- {
- analogWrite(1, 205); //Attiny85 pin 1 // 328 pin 10
- analogWrite(2, 255); //Attiny85 pin 4 // 328 pin 6 Green
- analogWrite(4, 255); //Attiny85 pin 3 // 328 pin 5 Yellow
- analogWrite (3, 0); //Attiny85 pin 3 // 328 pin 5 Red
- }
- else if (tempIn > tempOut + 6)
- {
- analogWrite(1, 255); //Attiny85 pin 1 // 328 pin 10
- analogWrite(2, 255); //Attiny85 pin 4 // 328 pin 6 Green
- analogWrite(3, 255); //Attiny85 pin 3 // 328 pin 5 Red
- analogWrite(4, 255); //Attiny85 pin 2 // 328 pin ? Yellow
- }
- else
- {
- analogWrite (1, 0); //Attiny85 pin 1 // 328 pin 10
- analogWrite (2, 0); //Attiny85 pin 3 // 328 pin 5 Green
- }
- }
- }// End printTemperature
- //*********( THE END )***********
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement