نمایش دما در برد Arduino Leonardo

#include  
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 
// the setup routine runs once when you press reset: 
long readTemp() 
{    
    // Read temperature sensor against 1.1V reference   
    #if defined(__AVR_ATmega32U4__)     ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0);     ADCSRB = _BV(MUX5); 
    // the MUX5 bit is in the ADCSRB register   
    #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)     ADMUX = _BV(REFS1) | _BV(MUX5) | _BV(MUX1);   
    #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)     ADMUX = _BV(REFS1) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0);   
    #else     ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX3);   #endif    delay(2); 
    // Wait for ADMUX setting to settle   
    ADCSRA |= _BV(ADSC); 
    // Start conversion   
    while (bit_is_set(ADCSRA,ADSC)); 
    // measuring    
    uint8_t low = ADCL; 
    // must read ADCL first - it then locks ADCH   
    uint8_t high = ADCH; 
    // unlocks both   
    long result = (high << 8) | low; 
    // combine the two    
    return result - 280; 
}  
void setup() 
{  
    
}  
// the loop routine runs over and over again forever: 
void loop() 
{   
    lcd.clear();   
    long tmp = readTemp();   
    lcd.print(tmp);   
    delay(500); 
} 

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

ده − دو =