Hello everyone I need some help on how to make an active program.
I have an encoder, Lcd, and DHT.
the program does not work because there is a return
how to bypass return
#include <Scheduler.h>
#include <DHT.h>
#include <LiquidCrystal.h>
#define DHT11_PIN 6
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int clkPin = 7; //the clk attach to pin 2
const int dtPin = 8; //the dt pin attach to pin 3
const int swPin = 9 ; //the sw pin attach to pin 4
int encoderVal = 0;
dht DHT;
void setup()
{
Serial.begin(9600);
pinMode(clkPin, INPUT);
pinMode(dtPin, INPUT);
pinMode(swPin, INPUT);
digitalWrite(swPin, HIGH);
Scheduler.startLoop(loop2);
lcd.begin(16, 2);
}
void loop()
{
lcd.setCursor(3, 0);
int change = getEncoderTurn();
encoderVal = encoderVal + change;
if (digitalRead(swPin) == LOW)
{
encoderVal = 0;
}
Serial.println(encoderVal);
lcd.setCursor(3, 0);
lcd.print(encoderVal);
lcd.print(" ");
}
void loop2();
{
int chk = DHT.read11(DHT11_PIN);
lcd.setCursor(0, 1);
lcd.print("T");
lcd.setCursor(1, 1);
lcd.println(DHT.temperature);
lcd.setCursor(9, 1);
lcd.print("H");
lcd.setCursor(10, 1);
lcd.print(DHT.humidity);
delay(1500);
yield();
}
int getEncoderTurn(void)
{
static int oldA = HIGH; //set the oldA as HIGH
static int oldB = HIGH; //set the oldB as HIGH
int result = 0;
int newA = digitalRead(clkPin);//read the value of clkPin to newA
int newB = digitalRead(dtPin);//read the value of dtPin to newB
if (newA != oldA || newB != oldB)
{
// something has changed
if (oldA == HIGH && newA == LOW)
{
result = (oldB * 2 - 1);
}
}
oldA = newA;
oldB = newB;
return result;
}