Hi, I am still exploring this interesting code, but I met this problem today.
I tried to use API to get real-time wind data from a website, but the free plan only allows me to request data 500 times a day.
So I was wondering if there is any way to make my loadData() run every 3 minutes.
Thanks
float x;
float y;
float wd;
float ws;
float tw;
JSONObject json;
String q = "Hello,world";
String url = "https://api.weatherbit.io/v2.0/current?lat=78.13&lon=15.38&key=";
void setup(){
size(1920,1080);
fill(0);
x = width/2;
y = 100;
loadData();
}
void draw(){
background(255);
x += cos(radians(wd))*(ws);
y += sin(radians(wd))*(ws);
translate(x, y);
rotate(radians(wd));
textSize(ws*10);
tw = textWidth(q);
text(q, 0, 0, tw+1, 800);
if (x < 0){
x = width;
}
if (x > width){
x = 0;
}
if (y > height){
y = 0;
}
if (y < 0){
y = height;
}
}
void loadData(){
json = loadJSONObject(url);
JSONArray weatherdata = json.getJSONArray("data");
for (int i = 0; i < weatherdata.size(); i++){
JSONObject data = weatherdata.getJSONObject(i);
wd = data.getInt("wind_dir");
ws = data.getFloat("wind_spd");
}
}