SHARE
TWEET

Untitled

a guest Dec 23rd, 2018 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Arduino.h>
  2.  
  3. /*
  4.   DS18B20 Pinout (Left to Right, pins down, flat side toward you)
  5.   - Left   = Ground
  6.   - Center = Signal (Pin 2):  (with 3.3K to 4.7K resistor to +5 or 3.3 )
  7.   - Right  = +5 or +3.3 V
  8.    
  9. /*-----( Import needed libraries )-----*/
  10. // Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
  11. #include <OneWire.h>
  12.  
  13. //Get DallasTemperature Library here:  http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
  14. #include <DallasTemperature.h>
  15. #include <util/delay.h>
  16. #include <avr/io.h>
  17.  
  18. /*-----( Declare Constants and Pin Numbers )-----*/
  19.  
  20. #define ONE_WIRE_BUS_PIN 0
  21. #define F_CPU 8000000  // This is used by delay.h library
  22.  
  23.  
  24. /*-----( Declare objects )-----*/
  25. // Setup a oneWire instance to communicate with any OneWire devices
  26. OneWire oneWire(ONE_WIRE_BUS_PIN);
  27.  
  28. // Pass our oneWire reference to Dallas Temperature.
  29. DallasTemperature sensors(&oneWire);
  30.  
  31. /*-----( Declare Variables )-----*/
  32. // Assign the addresses of your 1-Wire temp sensors.
  33. // See the tutorial on how to obtain these addresses:
  34. // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
  35.  
  36. DeviceAddress Probe01 = { 0x28, 0xFF, 0x57, 0xED, 0xB5, 0x16, 0x03, 0x75 };
  37. DeviceAddress Probe02 = { 0x28, 0xFF, 0x4D, 0x93, 0xC1, 0x16, 0x04, 0xFB };
  38.  
  39.  
  40. void setup()   /****** SETUP: RUNS ONCE ******/
  41. {
  42.  
  43.  
  44.     /*
  45.     Control Register A for Timer/Counter-0 (Timer/Counter-0 is configured using two registers: A and B)
  46.     TCCR0A is 8 bits: [COM0A1:COM0A0:COM0B1:COM0B0:unused:unused:WGM01:WGM00]
  47.     2<<COM0A0: sets bits COM0A0 and COM0A1, which (in Fast PWM mode) clears OC0A on compare-match, and sets OC0A at BOTTOM
  48.     2<<COM0B0: sets bits COM0B0 and COM0B1, which (in Fast PWM mode) clears OC0B on compare-match, and sets OC0B at BOTTOM
  49.     3<<WGM00: sets bits WGM00 and WGM01, which (when combined with WGM02 from TCCR0B below) enables Fast PWM mode
  50.     */
  51.  //   TCCR0A = 2<<COM0A0 | 2<<COM0B0 | 3<<WGM00;
  52.    
  53.     /*
  54.     Control Register B for Timer/Counter-0 (Timer/Counter-0 is configured using two registers: A and B)
  55.     TCCR0B is 8 bits: [FOC0A:FOC0B:unused:unused:WGM02:CS02:CS01:CS00]
  56.     0<<WGM02: bit WGM02 remains clear, which (when combined with WGM00 and WGM01 from TCCR0A above) enables Fast PWM mode
  57.     1<<CS00: sets bits CS01 (leaving CS01 and CS02 clear), which tells Timer/Counter-0 to not use a prescalar
  58.     */
  59. //    TCCR0B = 0<<WGM02 | 1<<CS00;
  60.    
  61.     /*
  62.     Control Register for Timer/Counter-1 (Timer/Counter-1 is configured with just one register: this one)
  63.     TCCR1 is 8 bits: [CTC1:PWM1A:COM1A1:COM1A0:CS13:CS12:CS11:CS10]
  64.     0<<PWM1A: bit PWM1A remains clear, which prevents Timer/Counter-1 from using pin OC1A (which is shared with OC0B)
  65.     0<<COM1A0: bits COM1A0 and COM1A1 remain clear, which also prevents Timer/Counter-1 from using pin OC1A (see PWM1A above)
  66.     1<<CS10: sets bit CS11 which tells Timer/Counter-1  to not use a prescalar
  67.     */
  68. //    TCCR1 = 0<<PWM1A | 0<<COM1A0 | 1<<CS10;
  69.    
  70.     /*
  71.     General Control Register for Timer/Counter-1 (this is for Timer/Counter-1 and is a poorly named register)
  72.     GTCCR is 8 bits: [TSM:PWM1B:COM1B1:COM1B0:FOC1B:FOC1A:PSR1:PSR0]
  73.     1<<PWM1B: sets bit PWM1B which enables the use of OC1B (since we disabled using OC1A in TCCR1)
  74.     2<<COM1B0: sets bit COM1B1 and leaves COM1B0 clear, which (when in PWM mode) clears OC1B on compare-match, and sets at BOTTOM
  75.     */
  76. //    GTCCR = 1<<PWM1B | 2<<COM1B0;
  77.  
  78.  
  79. /////////////////////////////////////////////////////////////////////////////////////////
  80. /*
  81.   // start serial port to show results
  82.  Serial.begin(9600);
  83.  Serial.print("Initializing Temperature Control Library Version ");
  84.  Serial.println(DALLASTEMPLIBVERSION);
  85. */
  86. ///////////////////////////////////////////////////////////////////////////////////////
  87.  
  88.   // Initialize the Temperature measurement library
  89.   sensors.begin();
  90.  
  91.   // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  92.   sensors.setResolution(Probe01, 10);
  93.   sensors.setResolution(Probe02, 10);
  94.  
  95. //TCCR1B = TCCR1B & 0b11111000 | 0x05; //set divider for the 328
  96. TCCR0B = TCCR0B & 0b11111000 | 0b001 ; // set to divide-by-1 prescale ATTiny
  97.  
  98. }//--(end setup )---
  99.  
  100. void loop()   /****** LOOP: RUNS CONSTANTLY ******/
  101. {
  102.  
  103. // delay(5000); // This delay will no longer work with new clock settings
  104. _delay_ms(30000); // So we use this one
  105.  
  106. ////////////////////////////////////////////////////////////////////////////////////
  107. /*
  108.  Serial.println();
  109.  Serial.print("Number of Devices found on bus = ");  
  110.  Serial.println(sensors.getDeviceCount());  
  111.  Serial.print("Getting temperatures... ");  
  112.   Serial.println();  
  113. */
  114. ////////////////////////////////////////////////////////////////////////////////////  
  115.   // Command all devices on bus to read temperature  
  116.   sensors.requestTemperatures();  
  117.  
  118.  //Serial.print("Probe 01 temperature is:   ");
  119.  printTemperature(Probe01);  
  120.  //Serial.println();
  121.  
  122.  
  123. }//--(end main loop )---
  124.  
  125.  
  126. /*-----( Declare User-written Functions )-----*/
  127. void printTemperature(DeviceAddress temps)
  128. {
  129.  
  130. float tempOut = sensors.getTempC(Probe01);
  131. float tempIn = sensors.getTempC(Probe02);
  132. {
  133.  
  134. /*
  135.    if (tempIn == -127.00)
  136.    {
  137.    Serial.print("Error getting temperature  ");
  138.    }
  139.    else
  140.    {
  141.  
  142.    Serial.print("TI: ");
  143.    Serial.print(tempIn);
  144.    Serial.println();
  145.    Serial.print("TO: ");
  146.    Serial.print(tempOut);
  147.    }
  148.  
  149. */
  150.  
  151. if (tempIn > tempOut +1.5 && tempIn <= tempOut + 4)
  152. {
  153.   analogWrite(1, 155);  //Attiny85 pin 1 // 328 pin 10
  154.   analogWrite (2, 255); //Attiny85 pin 3 // 328 pin 5 Green
  155.   analogWrite (3, 0); //Attiny85 pin 3 // 328 pin 5 Red
  156.   analogWrite (4, 0); //Attiny85 pin 3 // 328 pin 5 Yellow
  157.  
  158. }
  159. else if (tempIn > tempOut + 4 && tempIn <= tempOut +6)
  160. {
  161.   analogWrite(1, 205); //Attiny85 pin 1 // 328 pin 10
  162.   analogWrite(2, 255);  //Attiny85 pin 4 // 328 pin 6 Green
  163.   analogWrite(4, 255);  //Attiny85 pin 3 // 328 pin 5 Yellow
  164.   analogWrite (3, 0); //Attiny85 pin 3 // 328 pin 5 Red
  165.  }
  166.  
  167. else if (tempIn > tempOut + 6)
  168. {
  169.   analogWrite(1, 255); //Attiny85 pin 1 // 328 pin 10
  170.   analogWrite(2, 255);  //Attiny85 pin 4 // 328 pin 6 Green
  171.   analogWrite(3, 255);  //Attiny85 pin 3 // 328 pin 5 Red
  172.   analogWrite(4, 255);  //Attiny85 pin 2 // 328 pin ? Yellow
  173. }
  174.  
  175. else
  176.  {
  177.   analogWrite (1, 0); //Attiny85 pin 1 // 328 pin 10
  178.   analogWrite (2, 0); //Attiny85 pin 3 // 328 pin 5 Green
  179.  }
  180.  
  181.  
  182. }
  183.    
  184. }// End printTemperature
  185. //*********( THE END )***********
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top