4_Ust-vo_poluchenia_velichi.../main.c

57 lines
1.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <avr/interrupt.h>
#include <avr/io.h>
//#define F_CPU 1000000UL
int enc_val, last_enc_val;
long dht_Draw_idle=0;
bool dht_enabled = false;
#include "DHT_22.h"
#include "Encoder.h"
#include "timers.h"
// Настройка
void setup() {
// Инициализируем UART
Serial.begin(57600);
encoder_setup();
// Настраиваем таймер
setup_timer();
// Разрешаем прерывания
sei();
Serial.println("Start system");
delay(10);
DDRD = 0b10000000;
}
// Основной цикл
void loop() {
// Читаем данные с DHT
dht_enabled = dht_check();
dht_Draw_idle++;
if ( dht_Draw_idle>160000 ){
dht_Draw_idle = 0;
if ( dht_enabled ){
Serial.print( dht_humidity() );
Serial.print("% ");
Serial.print( dht_temperature() );
Serial.println("C");
}
}
// Serial.println("Enc [" + (String)enc_val + "] ");
enc_val = encoder_value();
bool Draw = false;
if (enc_val != last_enc_val) {
Draw = true;
last_enc_val = enc_val;
}
if (Draw) {
Serial.println("Enc [" + (String)enc_val + "] ");
}
}