Hello, I have a question about a index for a weather station.
I have some images of an sun, moon, cloud, rain, ect.
and I want to create a arduino code that when the barometric pressure in between like 1020-2030 hPa that I than see the sun on my lcd.
is there an index when I must see the sun, clouds, or rain.
Like:
970-990 = rain
1000-1010 = clouds
10020-1040 = sun
etc.
thanks
Hi!
there is several solutions I guess, so you can choose one that best fit to your needs.
Let's get the output value from the barometer, and convert it into a small range of value, each one of its last value will correspond to one picture you want to draw on your screen.
The simpler (but not smartest) method is to filter value with IF statment, for example:
int pressure; // contains your pressure value, let's say between 970 and 1040
if (pressure >970 && pressure <990){
print(rain_logo);
}
if (pressure >990 && pressure <1010){
print(cloud_logo);
}
....
just take care with the range you choose (here in my example, the exact value of 990 will not trigger the IF statment)
a smarter way: a direct conversion from pressure value with the command map()
. It is cool to code, but you may be more limited in your choice (the interval of value must be the same for each logo)
map(pressure, 970,1040,1,3);
this function will return a value from 1 to 3, for a pressure ranges from 970 to 1040.
you can use this value returned to select the correct logo to draw.
if (map(pressure, 970,1040,1,3) == 0){
print(rain_logo);
}
if (map(pressure, 970,1040,1,3) == 1){
print(cloud_logo);
}
......
Note I will keep silence on how you can draw the logo itself. I assume your issue was not here.
Hope it will help!
Maybe something like:
if(hPa > 1020)
{
show(Sun);
}
else if(hPa > 1000)
{
show(Clouds);
}
else if(hPa > 970)
{
show(Rain);
}
else
{
show(Hurricane watch):
}
Oke but I want it also with the "time" to it that if it is day time that I see a sun
And in the evening I have a moon.... and so on.
That must by also posible right?
Yes that is possible.
sure!
with the proposed solutions (and @JCA34F's is far better than mine cuz simplier and easy to read), you can cross data with another values.
Imagine a first loop selecting if it is day or night, then an included loop will select the correct logo according to the pressure value:
if (day == true){
if(hPa > 1020)
{
show(Sun);
}
else if(hPa > 1000)
{
show(Clouds);
}......
} else { // means: it is night time
if(hPa > 1020)
{
show(Moon);
}
else if(hPa > 1000)
{
show(Clouds_night);
}....
}
of course the "day" value needs to be setup by your card by any mean (RTC, internet access....)
Hello pvdbos
Try this easy maintainable switch/case construct for your project.
switch (index)
{
case 970 ... 990:
Serial.println("rain");
break;
case 1000 ... 1010:
Serial.println("clouds");
break;
case 1020 ... 1040:
Serial.println("sun");
break;
default:
Serial.println("unknown index or etc.");
break;
}
Have a nice day and enjoy coding in C++.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.