There is a 10k resistor to the 5 V pin on the arduino board. Additonally is and old 1 k resistor and a switch.
If the switch is closed then is the input on high level.
But I see, if the switch is open then is the port indefinite. It has to be changed in the final construction
But the while problem is in each switch position. In one of that positions is all correct, there should it work.
VG
mgbd
mgbd:
There is a 10k resistor to the 5 V pin on the arduino board. Additonally is and old 1 k resistor and a switch.
If the switch is closed then is the input on high level.
But I see, if the switch is open then is the port indefinite. It has to be changed in the final construction
But the while problem is in each switch position. In one of that positions is all correct, there should it work.
VG
mgbd
10k from where to where?
switch from where to where?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks.. Tom...
here is the (shorted) code, I hope you can identfy my failure:
// while-Problem-2 4.12.16
#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int eepromaddress = 0; // <--------- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
byte eepromwert;
LiquidCrystal_I2C lcd(0x20,16,2); // Achtung: auf den neuen I2C-LCD gibt es Adressjumper.
// Alle gesetzt, gibt I2C-Adresse 0x27 (ox20?),
#define LEDpin 13
int sensorpin1 = 8; // Vorlauf Anschluß des SMT160-30
int sensorpin2 = 12; // außen
#define relaypin 9 // Heizungsrelais
int cyclen = 2500; // wie oft wird ein Sensor abgefragt, bis daraus ein Mittelwert gebildet wird
float high, low; // float -3.4 E38 bis +3.8 E38 (4 Byte)
float High, Low;
float Temp, Temp1 ,Temp2;
int i; // +/- 32768 (2byte)
float a; // wird für die Ziffernausgabe benötigt
int eepromintervall = 1; // nach wieviel LCD-Ausgaben wird ein Wert ins EEPROM geschrieben <------- XXXXXXXXXXXXXXXXX
byte highbyte, lowbyte;
int relaypinstatus = 1;
int letzterrelaypinstatus = 0;
int ausschaltzaehler = 0;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// |||||||| ... Hier startet der Versuch der Relaisabfrage ||||||||||||||||||||||||||||||||||||||||
while(relaypinstatus == LOW)
{
relaypinstatus = digitalRead(relaypin);
};
lcd.println(relaypinstatus);
}
//....snip (many instructions)
while(relaypinstatus == HIGH)
{
relaypinstatus = digitalRead(relaypin);
};
} // End of loop XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Corrected sketch. It always displays '1'. Did you expect any different?
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 16, 2); // Achtung: auf den neuen I2C-LCD gibt es Adressjumper.
// Alle gesetzt, gibt I2C-Adresse 0x27 (ox20?),
#define relaypin 9 // Heizungsrelais
int relaypinstatus = 1;
void setup() {
// put your setup code here, to run once:
pinMode(relaypin, INPUT_PULLUP); // or INPUT depending on wiring
}
void loop() {
// |||||||| ... Hier startet der Versuch der Relaisabfrage ||||||||||||||||||||||||||||||||||||||||
while (relaypinstatus == LOW) {
relaypinstatus = digitalRead(relaypin);
};
// HERE relaypinstatus IS ALWAYS 1
lcd.println(relaypinstatus);
//....snip (many instructions)
while (relaypinstatus == HIGH) {
relaypinstatus = digitalRead(relaypin);
};
// HERE relaypinstatus IS ALWAYS 0
} // End of loop XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX