Автор Тема: Arduino pro mini + LCD 2x16 + 18b20  (Прочетена 5025 пъти)

Dafyz

  • Новодошъл
  • *****
  • Публикации: 1
    • Профил
Arduino pro mini + LCD 2x16 + 18b20
« -: Декември 07, 2013, 08:18:11 pm »
Здравейте колеги,
от няколко месеца се боря с това ... идеята е следната : да следя температура на антифриза, маслото, налягане на маслото и напрежение на акумулатора ... така звучи страшно, но не е чак толкова
за датчици за температура избрах 18б20
до тук звучи лесно, обаче идеята беше с Бутон да сменям 2х2 реда на дисплея ... и бутона е светещ/натискам бутона 1 светва и сменя състоянието на дисплея изкарва първите 2 реда, натискам пак и бутона изгасва и показва 2-рите 2 реда ....

и тук става кашата ...  трепти ужасно дисплея ... като рефрешва параметрите от 18б20
може би кода който ще приложа е виновен тъй като когато напиша да показва само 1 параметър няма проблеми ...  и бутона сработва когато си иска, а бутона е рафи, не е проблемен той... като задаржа малко и пусна нещата се случват ...

ето кода:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>

// Il terminale data del sensore è connesso
// alla porta 2 di Arduino
#define ONE_WIRE_BUS 10
// Imposta la comunicazione oneWire per comunicare
// con un dispositivo compatibile
OneWire oneWire(ONE_WIRE_BUS);

// Passaggio oneWire reference alla Dallas Temperature.
DallasTemperature sensors(&oneWire);
// this constant won't change:
const int  buttonPin = 9;    // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(void)
{
  // Start up the library
  sensors.begin();
  // Imposta il valore di righe e colonne del display LCD
   lcd.begin(16, 2);
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);
}

void loop(void)
{
 
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
    }
    else {
       // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off");
      }
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;

  // turns on the LED every four button pushes by
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of
  // the division of two numbers:
  if (buttonPushCounter % 2 == 0) {
  digitalWrite(ledPin, HIGH);
  sensors.requestTemperatures(); // Invia il comando di lettura delle temperatura
  lcd.clear();
  lcd.setCursor(0, 0); // bottom left
  lcd.print("water : ");
  lcd.print (sensors.getTempCByIndex(0));
  lcd.print(" C    ");
  lcd.setCursor(0, 1); // bottom left
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    int sensorValue1 = analogRead(A1);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage1 = sensorValue1 / 18.26 ;
    lcd.print("volt  : ");
    lcd.print(voltage1);
    lcd.print(" V    ");
   
      } else {
       
   lcd.setCursor(0, 0);
    // read the input on analog pin 7
  sensors.requestTemperatures(); // Invia il comando di lettura delle temperatura
    // print out the value you read:
    lcd.print("Oil temp:");
    lcd.print (sensors.getTempCByIndex(1));
    lcd.print("C  ");
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    int sensorValue3 = analogRead(A3);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage3 = sensorValue3 * (10/18.26);
    // print out the value you read:
    lcd.print("Oil pres:"); 
    lcd.print(voltage3);   
    lcd.print("Bar  ");
   
   digitalWrite(ledPin, LOW);
  }
}


Ще съм благодарен ако ме насочите къде бъркам и с взаимни усилия да го оправим ...





« Последна редакция: Декември 08, 2013, 01:48:27 pm от Dafyz »