Loading from TXT and implementing into my current code

Hello all. As some of you may know, it is the month of Ramadan. As a challenge, I decided to make a Ramadan app, and a desktop version of the app. Currently its programmed with all the prayer times for the duration of Ramadan, however I would like to make the program have the ability to continue working after Ramadan, without me having to key in the times manually (As of right now, my code functions under the principle of it requiring the hour and minute of the prayer).

Here is my current code:

import processing.sound.*;
SoundFile Athan;
PFont font, newFont;

//TechMasterRamadanTrackerVb1.0

//TechMasterSizeDeteccVaribles
int shiftRegister = 0;
float[]textPlacement = {640, 400, 960, 75, 1480, 100, 1110, 75};
float[] timeToPlacement = {640, 300, 960, 125, 1480, 150, 1110, 125};
float[] iftaarTime = {640, 200, 960, 175, 1480, 200, 1110, 175};
float[] timeRemaining = {640, 355, 960, 225, 1480, 250, 1110, 225};
float[] cautionTimer = {640, 300, 960, 250, 1480, 300, 1110, 275};
float[] nextPrayer = {640, 450, 960, 250, 1480, 300, 1110, 275};
String[] prayerList = {"Duhur", "Asr", "Maghrib", "Ishaa", "Fajr"};
//Time Varibles
int minsLeft = 0, hoursLeft = 0, hoursLeft2 = 0, minsLeft2 = 0, prayerStat = 0;

int aDay, iftaarHour = 20, iftaarDisplay = 8, startDay = 24;
int iftaarMinute[] = {16, 17, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 48};
int suhoorHour = 4;
int suhoorMinute[] = {43, 41, 39, 37, 36, 34, 32, 31, 29, 28, 26, 24, 23, 21, 20, 18, 17, 15, 14, 13, 11, 10, 9, 7, 6, 5, 4, 3, 2, 1, 1};

int duhurHour = 13;
int duhurMinute[] = {22, 21, 21, 21, 21, 21, 21, 21, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20};

int asrHour = 17;
int asrMinute[] = {8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 17, 17, 17, 18, 18, 18};

int ishaaHour = 21;
int ishaaMinute[] = {16, 17, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 48};
//misc varibles
String toggleText = "ISNA", supscr  = "";

int s = 0, numFrames = 111, currentFrame = 0, colour = 191, day, mas;
boolean suhoorStat = false, iftaarStat = true, hourStat = true, startupStatus = false, toggleValue = false, isnaStat = true, timeto = false, athanStat = false, hilalStart;

PImage[] images = new PImage[numFrames]; //intro animation array
void settings() {
  fullScreen();
  techMasterTimeCalccSuhoor();
  if (hoursLeft == 0) {
    hourStat = false;
  }
  size(1280, 720);
}
void setup() {
  font = loadFont("SFProDisplay-Bold-25.vlw");
  newFont = loadFont("SFProDisplay-Bold-50.vlw");

  if (month() == 4) {
    aDay = day() - 24;
  } else if (month() == 5) {
    aDay = 6 + day();
  } //calculates day of ramadan, likely to be changed when more days are added

  textSize(25);
  Athan = new SoundFile(this, "Athan1.wav"); //The athan sound/call to prayer
  textAlign(CENTER);
  background(0);
  imageMode(CENTER);
  for (int i = 0; i < images.length; i++) {
    String imageName = "image" + nf(i, 3) + ".png";  
    //Load images
    images[i] = loadImage(imageName);
  }
}
void draw() {
  techMasterSizeDeteccV2(); //Detects screen size and adjusts location of elements based on that

  int[] nextPrayer = {640, 440, 960, 250, 1480, 300, 1110, 275};

  int Rday = day() - startDay;
//Adds depreciated "st/th" to end of day number
  if (aDay == 0 || aDay == 20) {
    supscr = "st";
  } else if (aDay == 1 || aDay == 21) {
    supscr = "nd";
  } else if (aDay == 2 || aDay == 22) {
    supscr = "rd";
  } else {
    supscr = "th";
  }

  if (!startupStatus) {
    loadingScreen();
  } else {
    mainScreen();
  }
  athan();
}
void techMasterSizeDeteccV2() {
  float wid = width;
  float hei = height;
  textPlacement[0] = wid*0.5;
  textPlacement[1] = hei*0.555555556;
  timeToPlacement[0] = wid*0.5;
  timeToPlacement[1] = hei*0.416666667;
  iftaarTime[0] = wid*0.5;
  iftaarTime[1] = hei*0.493055556;
  timeRemaining[0] = wid*0.5;
  timeRemaining[1] = hei*0.277777778;
  cautionTimer[0] = wid*0.5;
  cautionTimer[1] = hei*0.225694444;
  nextPrayer[0] = wid*0.5;
  nextPrayer[1] = hei*0.625;
}
void techMasterSizeDetecc() { //Old size detector
  int wid = width;
  int hei = height;
  if (wid == 1920 && hei == 1080) {
    shiftRegister = 2;
  } else if (wid == 2560 && hei == 1440) {
    shiftRegister = 0;
  } else if (wid == 2960 && hei == 1440) {
    shiftRegister = 4;
  } else if (wid == 2220 && hei == 1080) {
    shiftRegister = 5;
  }
}

void loadingScreen() {
  image(images[currentFrame], width /2, height /2);
  currentFrame++;
  if (currentFrame == numFrames) {
    startupStatus = true;
  }
}
//the main screen
void mainScreen() {
  background(0);
  fill(15, 168, colour);
  rect(15, 15, 75, 100);
  int hour = hour();
  if (hour > 12) {
    hour = hour - 12;
  }
  int hourD = hour();
  int minute = minute();
  String min = str(minute);
  if (minute < 10) {
    min = nf(minute, 2);
  }
//Calculates which prayer is next
  if ((hourD >= iftaarHour && minute >= iftaarMinute[aDay]) || hourD >= iftaarHour) {
    techMasterTimeCalccSuhoor();
    iftaarStat = false;
    suhoorStat = true;
  } else {
    techMasterTimeCalccIftaar();

    iftaarStat = true;
    suhoorStat = false;
  } //even more prayer calculation
  if (hour() >= ishaaHour || hour() <= suhoorHour) {
    prayerStat = 4;
    suhoorStat = true;
    iftaarStat = false;
    if (hour() == suhoorHour) {
      if (minute() < suhoorMinute[aDay]) {
        prayerStat = 4;
        suhoorStat = true;
        iftaarStat = false;
      } else {
        prayerStat = 0;
        suhoorStat = false;
        iftaarStat = true;
      }
    }
  } else if (hour() >= suhoorHour && hour() <= duhurHour) { //More prayer calculation
    prayerStat = 0;
    if (hour() == duhurHour) {
      if (minute() < duhurMinute[aDay]) {
        prayerStat = 0;
      } else {
        prayerStat = 1;
      }
    }
  } else if (hour() >= duhurHour && hour() <= asrHour) {
    prayerStat = 1;
    if (hour() == asrHour) {
      if (minute() < asrMinute[aDay]) {
        prayerStat = 1;
      } else {
        prayerStat = 2;
      }
    }
  } else if (hour() >= asrHour && hour() <= iftaarHour) { //You get the idea
    prayerStat = 2;
    if (hour() == iftaarHour) {
      if (minute() < iftaarMinute[aDay]) {
        prayerStat = 2;
      } else {
        prayerStat = 3;
      }
    }
  } else if (hour() >= iftaarHour && hour() <= ishaaHour) {
    prayerStat = 3;
    if (hour() == ishaaHour) {
      if (minute() < ishaaMinute[aDay]) {
        prayerStat = 3;
      } else {
        prayerStat = 4;
      }
    }
  }
  if (prayerStat == 0) {
    techMasterTimeCalccDuhur();
    techMasterTimeCalccIftaar();
  } else if (prayerStat == 1) {
    techMasterTimeCalccAsr();
    techMasterTimeCalccIftaar();
  } else if (prayerStat == 2) {
    techMasterTimeCalccIftaar();
  } else if (prayerStat == 3) {
    techMasterTimeCalccIshaa();
    techMasterTimeCalccSuhoor();
  } else if (prayerStat == 4) {
    techMasterTimeCalccSuhoor();
  }
  int modifier = 0;
  if (!isnaStat) {
    modifier = 1;
  }
  fill(255);
  text(toggleText, 160, 100);
  String colon = " : ";
  if (isEven(second())) {
    colon = " : ";
  } else {
    colon = "   ";
  }
  int displayDay;
  if (isnaStat) {
    displayDay = aDay;
  } else {
    displayDay = aDay - 1;
  }
  String minC = str(minsLeft);
  if (minsLeft < 10) {
    minC = nf(minsLeft, 2);
  }
  if (minute == 0){
    minute = 12; 
  } //The main text you see
  textFont(newFont, 60);
  text(hour + colon + min, timeToPlacement[shiftRegister], timeToPlacement[shiftRegister + 1]);
  textFont(font, 30);
  text("Ramadan Day: " + (displayDay + 1), textPlacement[shiftRegister], textPlacement[shiftRegister + 1]);
  if (!athanStat) {
    text("Next Prayer: " + prayerList[prayerStat] + " " + "In " + hoursLeft2 + colon + minsLeft2, nextPrayer[shiftRegister], nextPrayer[shiftRegister + 1]);
  }
  if (athanStat) {
    text(prayerList[prayerStat] + "Athan is now", iftaarTime[shiftRegister], iftaarTime[shiftRegister+1]);
  } else if (suhoorStat) {
    text("Today, Fajr is at " + suhoorHour + ":" + suhoorMinute[aDay], iftaarTime[shiftRegister], iftaarTime[shiftRegister+1]);
    text(hoursLeft + colon + minC + " Remaining", timeRemaining[shiftRegister], timeRemaining[shiftRegister + 1]);
    if (minsLeft <= 5 && hoursLeft == 0) {
      fill(255, 0, 0);
      text("WARNING, LESS THAN 5 MINUTES REMAINING UNTIL FAJR. PROCEED WITH EXTREME CAUTION", cautionTimer[shiftRegister], cautionTimer[shiftRegister + 1]);
    }
  } else if (iftaarStat) {
    text("Today, Iftaar is at " + iftaarDisplay + ":" + iftaarMinute[aDay], iftaarTime[shiftRegister], iftaarTime[shiftRegister+1]);
    text(hoursLeft + colon + minC + " Remaining", timeRemaining[shiftRegister], timeRemaining[shiftRegister + 1]);
  }
}

/*
  text("Salam Alaikum and Ramadan Kareem. Welcome to TechMasterRamadanTracker", textPlacement[shiftRegister], textPlacement[shiftRegister + 1]);
 text("The time is now " + hour + " : " + min + ". It is " + Rday + "" + supscr + " Day of Ramadan", timeToPlacement[shiftRegister], timeToPlacement[shiftRegister + 1]);
 if (!isnaStat && !hilalStart) {
 text("Ramadan Has not Started yet", iftaarTime[shiftRegister], iftaarTime[shiftRegister+1]);
 } else {
 if (timeto) {
 if (Athan.isPlaying() && timeto) {
 text("The Athan is now. TechMaster Industries Reccomends you wait at least 2-5 minutes \nafter the Athan before you break your fast to ensure your fasting is counted", iftaarTime[shiftRegister], iftaarTime[shiftRegister+1]);
 } else if (timeto) {
 text("Today, Iftaar is at " + iftaarDisplay + ":" + iftaarMinute[day], iftaarTime[shiftRegister], iftaarTime[shiftRegister+1]);
 if (!hourStat) {
 text("There are approx. " + minsLeft + " minutes left until Iftaar", timeRemaining[shiftRegister], timeRemaining[shiftRegister + 1]);
 } else {
 text("There are approx." + hoursLeft + "hour(s) and " + minsLeft + " minutes left until Iftaar", timeRemaining[shiftRegister], timeRemaining[shiftRegister + 1]);
 }
 } else {
 text("Today, Fajr is at " + suhoorHour + ":" + suhoorMinute[day], iftaarTime[shiftRegister], iftaarTime[shiftRegister+1]);
 text("There are approx." + hoursLeft + "hour(s) and " + minsLeft + " minutes left until Fajr", timeRemaining[shiftRegister], timeRemaining[shiftRegister + 1]);
 if (minsLeft <= 5) {
 fill(255, 0, 0);
 text("WARNING, LESS THAN 5 MINUTES REMAINING UNTIL FAJR. PROCEED WITH EXTREME CAUTION", cautionTimer[shiftRegister], cautionTimer[shiftRegister + 1]);
 }
 }
 }
 }
 }
 */

void mousePressed() {
  if (startupStatus) {
    if (mouseX >= 15 && mouseX <= 315 && mouseY >= 15 && mouseY <= 165) {
      isnaStat = !isnaStat;
      if (isnaStat) {
        startDay = 24;
        colour = 191;
        toggleText = "ISNA";
      } else {
        startDay = 25;
        colour = 255; 
        toggleText = "HILAL";
        if (day() == 24) {
          hilalStart = false;
        } else {
          hilalStart = true;
        }
      }
    }
  }
}

void calculateTimeRemaining() {
  day = day() - 24;
  int minute = minute(), hour = hour(); 

  if (hour >= 5) {
    timeto = true;
    hoursLeft = iftaarHour - hour;
    minsLeft = iftaarMinute[day] - minute;
    if (minute > iftaarMinute[day]) {
      hoursLeft--; 
      minsLeft -= 60;
    }
    if (minsLeft < 0) {
      minsLeft = minsLeft * -1;
    }
  } else { 
    timeto = false;
    hoursLeft = suhoorHour - hour;
    minsLeft = suhoorMinute[day] - minute;
    if (minute > suhoorMinute[day]) {
      hoursLeft--; 
      minsLeft -= 60;
    }
    if (minsLeft < 0) {
      minsLeft = minsLeft * -1;
    }
  }
}

void techMasterTimeCalccIftaar() {
  day = day() - 24;
  int minute = minute(), hour = hour(); 
  int localMinLeft = 0;
  int localHourLeft = 0;
  localMinLeft = 60 - minute;
  localHourLeft --;
  localMinLeft += iftaarMinute[aDay];
  if (localMinLeft >= 60) {
    localHourLeft ++;
    localMinLeft = localMinLeft - 60;
  }
  localHourLeft = localHourLeft + (iftaarHour - hour());

  hoursLeft = localHourLeft;
  minsLeft = localMinLeft;
}

void techMasterTimeCalccDuhur() {
  day = day() - 24;
  int minute = minute(), hour = hour(); 
  int localMinLeft = 0;
  int localHourLeft = 0;
  localMinLeft = 60 - minute;
  localHourLeft --;
  localMinLeft += duhurMinute[aDay];
  if (localMinLeft >= 60) {
    localHourLeft ++;
    localMinLeft = localMinLeft - 60;
  }
  localHourLeft = localHourLeft + (duhurHour - hour());

  hoursLeft2 = localHourLeft;
  minsLeft2 = localMinLeft;
}

void techMasterTimeCalccAsr() {
  day = day() - 24;
  int minute = minute(), hour = hour(); 
  int localMinLeft = 0;
  int localHourLeft = 0;
  localMinLeft = 60 - minute;
  localHourLeft --;
  localMinLeft += asrMinute[aDay];
  if (localMinLeft >= 60) {
    localHourLeft ++;
    localMinLeft = localMinLeft - 60;
  }
  localHourLeft = localHourLeft + (asrHour - hour());

  hoursLeft2 = localHourLeft;
  minsLeft2 = localMinLeft;
}

void techMasterTimeCalccIshaa() {
  day = day() - 24;
  int minute = minute(), hour = hour(); 
  int localMinLeft = 0;
  int localHourLeft = 0;
  localMinLeft = 60 - minute;
  localHourLeft --;
  localMinLeft += ishaaMinute[aDay];
  if (localMinLeft >= 60) {
    localHourLeft ++;
    localMinLeft = localMinLeft - 60;
  }
  localHourLeft = localHourLeft + (ishaaHour - hour());

  hoursLeft2 = localHourLeft;
  minsLeft2 = localMinLeft;
}

void techMasterTimeCalccSuhoor() {
  day = day() - 24;
  int minute = minute(), hour = hour(); 
  int localMinLeft = 0;
  int localHourLeft = 0;
  //else if (Athan.isPlaying()) {
  //timeto = true;
  timeto = false; 
  if (hour !=0) {
    localMinLeft = 60 - minute;
    localHourLeft --;
    localHourLeft += 24 - hour;
    localMinLeft += suhoorMinute[aDay];
    if (localMinLeft >= 60) {
      localHourLeft ++;
      localMinLeft = localMinLeft - 60;
    }
    localHourLeft += suhoorHour;
  } else {
    localMinLeft = 60 - minute;
    localHourLeft --;
    localMinLeft += suhoorMinute[aDay];
    if (localMinLeft >= 60) {
      localHourLeft ++;
      localMinLeft = localMinLeft - 60;
    }
    localHourLeft = localHourLeft + (suhoorHour - hour());
  }
  hoursLeft = localHourLeft;
  minsLeft = localMinLeft;
  if (prayerStat == 4) {
    hoursLeft2 = localHourLeft;
    minsLeft2 = localMinLeft;
  }
}
void athan() {
  int hour = hour();
  int min = minute();
  if ((hour == iftaarHour && min == iftaarMinute[day] && !Athan.isPlaying())) {
    Athan.play();
  } else if (hour == suhoorHour && min == suhoorMinute[day] && !Athan.isPlaying()) {
    Athan.play();
  }
}
boolean isEven(int n) {
  return n % 2 == 0;
}

My first idea was loading prayer times from a text file with formatting similar to this:

Thu 14 May
04:17
13:15
17:15
20:39
22:13
Fri 15 May
04:15
13:15
17:15
20:40
22:15
Sat 16 May
04:14
13:15
17:16
20:41
22:16
Sun 17 May
04:12
13:15
17:16
20:42
22:18
Mon 18 May
04:11
13:15
17:17
20:43
22:19
Tue 19 May
04:09
13:15
17:17
20:44
22:21
Wed 20 May
04:08
13:15
17:17
20:45
22:23
Thu 21 May
04:06
13:15
17:18
20:46
22:24
Fri 22 May
04:05
13:15
17:18
20:47
22:26

However I am at a loss as to how to use loadStrings() or createReader to parse through this and implement it into my code

Any ideas on the topic? Am I even using the right approach? Is there a better solution?

Thanks for the help in advance

1 Like

Hi @TechMaster04 – is your goal to display the data in the text file, or to make a computation with it – for example, have the screen color change when the day / hour / minute matches – or both?