Rendetlenkedő programok

saua
Újonc
Újonc
Hozzászólások: 7
Csatlakozott: 2015. április 17. péntek, 16:39

Rendetlenkedő programok

Hozzászólás Szerző: saua »

Sziasztok


Egy termosztát programmal kísérletezgetek. A program működését csak nagyjából értem.

Kód: Egész kijelölése

#include <EEPROM.h>
 #include <LiquidCrystal.h>// include the library code
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 6 on the Arduino
#define ONE_WIRE_BUS 6
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
 int led =9; // led is at pin
 int temp;  // make a variable called temp
 int settemp; // make a variable called temp
 int swtu = 7;  // switch up is at pin 7
 int swtd = 8;   // switch down is at pin 8
 LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // lcd is at 12,11,5,4,3,2

 void setup() {
   pinMode (led,1);  // make led or pin13 an output
   lcd.begin(16, 2); // set up all the "blocks" on the display
   lcd.setCursor(0,0); // set the cursor to colum 0 row 0
   lcd.print("Temp:"); 
   lcd.setCursor(12,0); 
   lcd.print((char)223);
   lcd.setCursor(13,0); 
   lcd.print("C");
   EEPROM.read (1); // make the eeprom or atmega328 memory address 1
 }

 void loop() {

sensors.requestTemperatures();   // beolvas a DS18B20- tol
   
   int temp = sensors.getTempCByIndex(0); 
   lcd.setCursor (9,0); 
   lcd.print (temp);  // Print the current temp 
   
      settemp = EEPROM.read(1); // read the settemp on the eeprom

   delay (250); // wait for the lcd to refresh every 250 milliseconds
  
   if             // if we se the switch up pin reading on 1 or 5 volts
     (digitalRead(swtu)== 1 )
   {
     settemp ++  // add one to the settemp, the settemp is the ideal temperature for you
    

       ;
   }

 else{// other wise do nothing

 }

 if
 (digitalRead (swtd) == 1)// if we detect a 1 on the other switch pin
 {
   (settemp --);// subtract one fromm the settemp
  
 }
 else {
 // else, do nothing
 }

 if (temp > settemp) // if the temperature exceeds your chosen settemp
 {
   digitalWrite (led, 1); // turn on the led
 }
 else // if that doesn't happen, then turn the led off
 {
   digitalWrite (led,0);
 }

 lcd.setCursor (0,1); // set the cursor to 0,1
 lcd.print ("Set to:"); // Print set to and your ideal temperature in f
  lcd.setCursor (9,1);
 lcd.print (settemp);
 lcd.setCursor(12,1); 
   lcd.print((char)223);
   lcd.setCursor(13,1); 
   lcd.print("C");
 
 EEPROM.write (1,settemp); /* write the most recent settemp in eeprom data stoage
   so that if the power is disconnected, you settemp is saved!*/
  
 delay (250); // wait 250 milliseconds

 } // we're done
Az egyik probléma, hogy bekapcsoláskor a kijelzőn egy pillanatra megjelenik a 85 fok, és a kimenetre ekkor logikai „1” kerül ami nagyon zavaró, hogy lehetne eltüntetni? a loop() a szenzor lekérdezésével kezdődik az első adat meg minden bekapcsoláskor a 85 fok.
Egy másik probléma, hogy az alaplapon levő13-as LED állandóan ég, fogalmam sincs miért.

A program eredetije itt található http://www.instructables.com/id/Arduino ... /?ALLSTEPS , ebbe piszkáltam bele, hogy tudjam használni a DS18B20 –al.
saua
Újonc
Újonc
Hozzászólások: 7
Csatlakozott: 2015. április 17. péntek, 16:39

Re: Rendetlenkedő programok

Hozzászólás Szerző: saua »

a másik fórumban kaptam választ, köszi.

"Először konverzió, utána hőfokkiolvasás...."

úgy látom, csak ez a két sor tartozik a szenzorhoz:
sensors.requestTemperatures();
int temp = sensors.getTempCByIndex(0);

ha ezt a két sort megcserélem nem változik semmi.
Avatar
Robert
Elektronbűvölő
Hozzászólások: 10191
Csatlakozott: 2005. december 9. péntek, 7:00

Re: Rendetlenkedő programok

Hozzászólás Szerző: Robert »

A függvénykönyvtáradban így van belül megírva. először kiolvas, utána konvertál.
Tedd a setup részbe az első kiolvasást.... Azt úgyse íratod ki :)
saua
Újonc
Újonc
Hozzászólások: 7
Csatlakozott: 2015. április 17. péntek, 16:39

Re: Rendetlenkedő programok

Hozzászólás Szerző: saua »

Köszi a választ

Csak úgy sikerült megoldani a problémát ha a kiolvasást, a konvertálást és még egy 1000 ms -os késleltetést is beírtam a setup részbe.
Avatar
Robert
Elektronbűvölő
Hozzászólások: 10191
Csatlakozott: 2005. december 9. péntek, 7:00

Re: Rendetlenkedő programok

Hozzászólás Szerző: Robert »

A libraryban a menetrend:
- kiolvasás
- mérés/konverzió indítása

Az hogy 1000 ms várakozást tettél be: a hőmérőid parazita módban vannak használva (tipp :))
Válasz küldése