Advertisement
Sadesign

Untitled

Dec 17th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <OneWire.h>
  2. OneWire oneWire (12);  
  3.  
  4. byte addrThermo5[] = {0x28, 0xFF, 0x9C, 0xF0, 0xC1, 0x16, 0x04, 0x70}; //адрес датчика 5
  5. float thermo5;   //показания термометра 5
  6.  
  7.  
  8. void setup()
  9. {
  10. Serial.begin(9600);      
  11. }
  12.  
  13. void loop()  
  14. {    
  15.   oneWire.reset();                    
  16. //oneWire.select (addrThermo5);   //КОД РАБОТАЕТ
  17.   oneWire.select (0xCC);          //КОД НЕ РАБОТАЕТ    
  18.   oneWire.write (0x44);        
  19.  
  20.   delay (1000);
  21.      
  22.   oneWire.reset();                //сбрасываем шину 1-Wire
  23.   oneWire.select (addrThermo5);   //выбираем нужный термодатчик по его адресу
  24.   oneWire.write (0xBE);           //отправляем в порт команду 0xBE (читать данные из датчика)
  25.  
  26.   byte data[9];
  27.   for (byte i = 0; i < 9; i++) {data[i] = oneWire.read();} //смотрим 9 байтов
  28.   int16_t raw = (data[1] << 8) | data[0];        
  29.   thermo5 = (float)raw / 16.0;                             //конвертим raw в градусы цельсия
  30.  
  31.   Serial.println( thermo5);      
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement