diff --git a/main.c b/main.c index 8cc5e2b..3feee11 100644 --- a/main.c +++ b/main.c @@ -1,23 +1,76 @@ -# include <Encoder.h> -# include <DHT_22.h> - - -void setup() -{ - encoder_Initialization(); - DHT22_setup(); - //Здесь функции ктр вызываются 1 раз -} - -void loop() -{ - Serial.print("Данные с энкодера: "); - Serial.print(get_encoder_value()); - Serial.print(""); - Serial.print("Темпеартура: "); - Serial.print(get_DHT_value_temperature()); - Serial.print(" "); - Serial.print("Влажность: "); - Serial.println(get_DHT_value_humidity()); - //Здесь функции ктр вызываются бесконечное количество раз +#include <avr/interrupt.h> +#include <avr/io.h> +//#define F_CPU 1000000UL + +// Определения портов и битов +#define DHT_PORT PORTB +#define DHT_DDR DDRB +#define DHT_PIN PINB +#define DHT_BIT 0 + +// Глобальные переменные +unsigned char data[5]; +byte dt[48]; +byte dtcnt; + + +float temperature, humidity; + int enc_val, last_enc_val; +float last_temperature, last_humidity; + +// Флаг прерывания +volatile unsigned char interrupt_flag = 1; +bool dht_check_act = false; +bool dht_done = false; +int dht_check_icp; + +byte dht_state, dht_last_state; +int T1time, dPos, dNum; + +//int dht_save_time[42]; +int dht_save_time_id; + +// Таймер для задержки +volatile unsigned int timer_counter = 0; +int dht_en_timer=0; + +void PrintDebug(); + +#include "timers.h" +#include "dht.h" +#include "enc.h" +// Настройка +void setup() +{ + // Инициализируем UART + Serial.begin(57600); + encoder_setup(); + // Настраиваем таймер + setup_timer(); + + // Разрешаем прерывания + sei(); + Serial.println("Start system"); + delay(10); + DDRD = 0b10000000; +} + +// Основной цикл +void loop() +{ + + // Читаем данные с DHT + dht_check(); + 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+"] "); + } } \ No newline at end of file