Hallo Leute,
ich Baue mir gerade ein UV-Meter und habe ein kleines Problem im Loopteil.
Das Problem sind die if Bedingungen.
Da sie ja alle erfüllt werden, laufen sie in Dauerschleife durch.
Das soll natürlich nicht sein. :~
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int val;
void setup()
{
Serial.begin(9600);// open serial port, set the baud rate to 9600 bps
}
void loop()
{
Serial.println(val);
lcd.begin(16,2);
lcd.setCursor(0, 0);
lcd.print("UV Index= ");
val = analogRead(0);
if (val < 10)
{
lcd.setCursor(11, 0);
lcd.print("0");
delay(1000);
}
val = analogRead(0);
if (val > 10)
{
lcd.setCursor(11, 0);
lcd.print("1");
delay(1000);
}
val = analogRead(0);
if (val > 46)
{
lcd.setCursor(11, 0);
lcd.print("2");
delay(1000);
}
val = analogRead(0);
if (val > 65)
{
lcd.setCursor(11, 0);
lcd.print("3");
delay(1000);
}
val = analogRead(0);
if (val > 83)
{
lcd.setCursor(11, 0);
lcd.print("4");
delay(1000);
}
val = analogRead(0);
if (val > 103)
{
lcd.setCursor(11, 0);
lcd.print("5");
delay(1000);
}
val = analogRead(0);
if (val > 124)
{
lcd.setCursor(11, 0);
lcd.print("6");
delay(1000);
}
val = analogRead(0);
if (val > 142)
{
lcd.setCursor(11, 0);
lcd.print("7");
delay(1000);
}
}