Bilder Upload
Follow Me!
#1

Variablenprobleme

in Software 02.09.2013 11:51
von carphunter
avatar

Hey Leute Smile

Ich habe ein kleines Problem...
Ich möchte auf einem LC Display die gemessene Temperatur (Variable "temperatur") ausgeben.

Mein Code sieht so aus:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
 
Code:
/* Temp Anfang!! */
int LM35 = A0;
float SensorValue = 0;
float temperatur = 0;
float temp[5];
/* Temp ENDE!! */
 
/* LCD Display Anfang!! */
#include <SoftwareSerial.h>
 
#define txPin 2
 
SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10; // conservative, 2 actually works
 

// wbp: goto with row & column
void lcdPosition(int row, int col) {
LCD.write(0xFE); //command flag
LCD.write((col + row*64 + 128)); //position
delay(LCDdelay);
}

void clearLCD(){
LCD.write(0xFE); //command flag
LCD.write(0x01); //clear command.
delay(LCDdelay);
}

void backlightOn() { //turns on the backlight
LCD.write(0x7C); //command flag for backlight stuff
LCD.write(157); //light level.
delay(LCDdelay);
}
 
void backlightOff(){ //turns off the backlight
LCD.write(0x7C); //command flag for backlight stuff
LCD.write(128); //light level for off.
delay(LCDdelay);
}

void serCommand(){ //a general function to call the command flag for issuing all other commands
LCD.write(0xFE);
}
/* LCD Display ENDE!! */

void setup() {
Serial.begin(9600); //temp

/* LCD Display Anfang!! */
pinMode(txPin, OUTPUT);
LCD.begin(9600);
clearLCD();
lcdPosition(0,0);
LCD.print(temperatur);
LCD.print(" Grad");
/* LCD Display ENDE!! */
}
 
void loop() {
/* Temp Anfang!! */
SensorValue = analogRead(LM35); //temp
temp[1] = (5.0 * analogRead(LM35) * 100.0) / 1024;
delay(1000); // 1 Sekunde Pause zwischen den Messungen machen
temp[2] = (5.0 * analogRead(LM35) * 100.0) / 1024;
delay(1000);
temp[3] = (5.0 * analogRead(LM35) * 100.0) / 1024;
delay(1000);
temp[4] = (5.0 * analogRead(LM35) * 100.0) / 1024;
delay(1000);
temp[5] = (5.0 * analogRead(LM35) * 100.0) / 1024;
 
temperatur = (temp[1] + temp[2] + temp[3] + temp[4] + temp[5])/5; //Mittelwert aus 5 Messungen bilden
//Serial.print(SensorValue, DEC);
//Serial.print(” –> “);
Serial.print(temperatur, 1); //Ausgabe der Temperatur mit einer Nachkommastelle
Serial.println("Grad Celsius");
/* Temp Ende */
}
 
 



Liege ich richtig, dass die Reihenfolge der Ausgabecodes nicht stimmt?

Weil mein LCD 0.00 Grad ausgiebt, was ja eigentlich die gesetzte globale Variable ist...

Kann mir jemand helfen, dass ich die schon berechnete Variable [temperatur] "vor" die Ausgabe des LCD bekomme?

Ich hoffe, ihr versteht, was ich meine Big Grin


Mfg und vielen Dank im Voraus
Carphunter

nach oben springen


Besucher
0 Mitglieder und 5 Gäste sind Online

Wir begrüßen unser neuestes Mitglied: hobbit23
Forum Statistiken
Das Forum hat 139 Themen und 222 Beiträge.

Xobor Forum Software von Xobor.de
Einfach ein Forum erstellen