• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Problem z enkoderem + wyswietlacz LCD
#1
Elo.
Przychodze z prosba o pomoc w rozwiazaniu nastepujacego problemu, mam zamiar zrobic cos na zasadzie termostatu ale do sterowania modulem peltiera. W tej chwili mam:
- Podlaczony LCD
- Podlaczony enkoder
- Podlaczony czujnik DS18B20
i w zawiazku z tym mam taki kod:

Kod:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire ourWire(ONE_WIRE_BUS);
DallasTemperature sensors(&ourWire);
int led=7;

int pinA = 10;  // Connected to CLK on KY-040
int pinB = 11;  // Connected to DT on KY-040
int encoderPosCount = 0;
int pinALast;  
int aVal;
boolean bCW;

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);

void setup()
{
   pinMode (pinA,INPUT);
  pinMode (pinB,INPUT);
  /* Read Pin A
  Whatever state it's in will reflect the last position  
  */
  pinALast = digitalRead(pinA);  
  Serial.begin (9600);

 
 // initialize the LCD
 lcd.begin();

 // Turn on the blacklight and print a message.
 lcd.backlight();
 sensors.begin();


  }

void loop() {

  aVal = digitalRead(pinA);
  if (aVal != pinALast){
    if (digitalRead(pinB) != aVal) {
      encoderPosCount ++;
      bCW = true;
    } else {
      bCW = false;
      encoderPosCount--;
    }
    Serial.print ("Rotated: ");
    if (bCW){
      Serial.println ("clockwise");
    }else{
      Serial.println("counterclockwise");
    }
    Serial.print("Encoder Position: ");
    Serial.println(encoderPosCount);
   
  }
  pinALast = aVal;
 
 float temp; //actual temperature
 int fine;  //desired temperature
 lcd.setCursor(0,0);
 sensors.requestTemperatures();

 //fine=((30*sensors.getTempCByIndex(0))/1024); //calculating the desired temp.
 fine=(sensors.getTempCByIndex(0));
 lcd.print("Temp finale:");  //printing it on lcd and serial monitor
 lcd.setCursor(12,0);
 lcd.print(encoderPosCount);

 Serial.print("Temp finale:");
 Serial.println(fine);

 lcd.setCursor(0, 1);

 lcd.print("Temp:");
 Serial.print("Temp attuale:");

 temp=(encoderPosCount); //calculating the actual temp.
 lcd.setCursor(11,1);
 lcd.print(temp);
 Serial.println(temp);

if(temp<fine){ //lighting up the led
   digitalWrite(led,HIGH);
 }
 else
   digitalWrite(led,LOW);

 //delay(200); //update frequency,otherwise the numbers on the lcd would flicker

}

Moj problem polega na tym ze na wyswietlaczu oprocz aktualnej temperatury chce widziec temperature zadana enkoderem ale dziala to tak ze czujnik temp ma odswierzanie co np 1s a w momencie krecenia enkoderem jestem wstanie przekrecic wiecej niz raz na 1s co powoduje ze jesli chce ustawic np 60 st. C to potrzebuje krecic 1min.
A drugi problem jest taki ze jak krece nim w lewo to odejmuje za kazdym razem a jak w prawo to raz dodaje raz odejmuje.
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości