#include long int set1; long int set2; long int set3; long int set4; long int j; String hours; String minutes; String seconds; int program; LiquidCrystal lcd(7,6, 5, 8, 3, 2); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7) int t1, t2, t3, t4, t5, t6; int r1, r2, r3; int s1, s2, s3; boolean feed = true; // condition for alarm char key; String r[8]; int cycle=1; int sequence=0; void setup() { analogWrite(9,40); //contrast lcd.begin(16,2); Serial.begin(9600); pinMode(A0, INPUT_PULLUP); pinMode(A1, INPUT_PULLUP); pinMode(A2, INPUT_PULLUP); pinMode(A3, INPUT_PULLUP); pinMode(A4, OUTPUT); } void loop() { // 1 open if(sequence==0&&cycle==1) { // 1,2 open lcd.setCursor(0,0); lcd.print(" TENS TIMER "); lcd.setCursor(0,1); lcd.print(" PRESS START "); } // 2 close, 1 open else { // 1,3 open lcd.setCursor(0,0); lcd.print(" TENS TIMER "); lcd.setCursor(0,1); lcd.print(" PRESS NEXT "); } // 3 close, 1 open if (digitalRead(A0)==0&&sequence==0&&cycle==1||digitalRead(A1)==0&&sequence==0&&cycle>1) // { // 1, 4 open int r[] = {0, 0, 3, 0, 0, 0}; sequence=1; int program = 2; lcd.clear(); // setFeedingTime(); for(int i = 0; i < 6; i++) // this for loop is used to get the value of the feeding time and print it serially { // 1,4,5 open Serial.print(r[i]); Serial.println(); } // 5 close, 1,4 open hours = String (r[0]) + String (r[1]) ; //combining two separate int values of r[0] and r[1] into one string and save it to "hours" minutes = String (r[2]) + String (r[3]) ; //combining two separate int values of r[2] and r[3] into one string and save it to "minutes" seconds = String (r[4]) + String (r[5]) ; //combining two separate int values of r[4] and r[5] into one string and save it to "seconds" /* hours = String(01); //combining two separate int values of r[0] and r[1] into one string and save it to "hours" minutes = String(00); //combining two separate int values of r[2] and r[3] into one string and save it to "minutes" seconds = String(00); //combining tw */ set1 = (hours.toInt()*3600); //converting hours into seconds set2 = (minutes.toInt() * 60); //converting minutes into seconds set3 = seconds.toInt(); set4 = (hours.toInt() * 3600)+ (minutes.toInt() * 60) + seconds.toInt(); //adding set1, set2 and set3 together in set4 Serial.print("set4"); Serial.print(set4); Serial.println(); lcd.setCursor(0,0); lcd.print("Countdown begins"); delay(1000); lcd.clear(); for(long int j = set4; j >= 0; j--) // this for loopis used to decrease the total time in seconds { // 1,4,6 open Serial.println(j); lcd.setCursor(0,0); lcd.print(" TENS TIMER P"); lcd.print(program); long int HH = j / 3600; // converting the remaining time into remaining hours lcd.setCursor(0,1); Serial.println(HH); if (HH < 10) { lcd.print('0'); } lcd.print(HH); lcd.print(":"); long int MM = (j - (HH*3600))/60 ; //converting the remaining time into remaining minutes lcd.setCursor(3,1); Serial.println(MM); if (MM < 10) { lcd.print('0'); } lcd.print(MM); lcd.print(":"); long int SS = j - ((HH*3600)+(MM*60)); //converting the remaining time into remaining seconds lcd.setCursor(6,1); Serial.println(SS); if (SS < 10) { lcd.print('0'); } lcd.print(SS); lcd.setCursor(9,1); lcd.print("cycle "); lcd.print(cycle); delay(1000); if (digitalRead(A2)==0){break;} if (j == 0) { // 1,4,6,7 open lcd.clear(); lcd.setCursor(0,0); lcd.print("Tens Timer Beep"); lcd.setCursor(1,1); lcd.print("End P2 cycle "); lcd.print(cycle); for(int k =0; k<= 200; k++) //this for loop is used for the buzzer to beep 200 time as the timer reaches zero { //1,4,6,7,8 open digitalWrite(A4,HIGH); delay(300); digitalWrite(A4,LOW); delay(300); if (digitalRead(A1)==0){break;} } // 8 close 1,4,6,7 open } // 7 close 1,4,6 open } // 6 close, 1,4 open } // 4 close, 1 open if(sequence==1) { // 1,9 open lcd.setCursor(0,0); lcd.print(" TENS TIMER "); lcd.setCursor(0,1); lcd.print(" PRESS NEXT "); } // 9 close 1 open //Serial.println(A3); if (digitalRead(A1)==0&&sequence==1) // // if (digitalRead(A0)==0&&sequence==0&&cycle==1||digitalRead(A1)==0&&sequence==0&&cycle>1) // { // 1,10 open int s[] = {0, 1, 0, 0, 0, 0}; sequence=0; program = 1; lcd.clear(); // setFeedingTime(); for(int i = 0; i < 6; i++) // this for loop is used to get the value of the feeding time and print it serially { // 1,10,11 open Serial.print(s[i]); Serial.println(); } // 11 close 1,10 open hours = String (s[0]) + String (s[1]) ; //combining two separate int values of r[0] and r[1] into one string and save it to "hours" minutes = String (s[2]) + String (s[3]) ; //combining two separate int values of r[2] and r[3] into one string and save it to "minutes" seconds = String (s[4]) + String (s[5]) ; //combining two separate int values of r[4] and r[5] into one string and save it to "seconds" /* hours = String(01); //combining two separate int values of r[0] and r[1] into one string and save it to "hours" minutes = String(00); //combining two separate int values of r[2] and r[3] into one string and save it to "minutes" seconds = String(00); //combining tw */ set1 = (hours.toInt()*3600); //converting hours into seconds set2 = (minutes.toInt() * 60); //converting minutes into seconds set3 = seconds.toInt(); set4 = (hours.toInt() * 3600)+ (minutes.toInt() * 60) + seconds.toInt(); //adding set1, set2 and set3 together in set4 Serial.print("set4"); Serial.print(set4); Serial.println(); lcd.setCursor(0,0); lcd.print("Countdown begins"); delay(1000); lcd.clear(); for(long int j = set4; j >= 0; j--) // this for loopis used to decrease the total time in seconds { // 1,10,12 open Serial.println(j); lcd.setCursor(0,0); lcd.print(" TENS TIMER P"); lcd.print(program); long int HH = j / 3600; // converting the remaining time into remaining hours lcd.setCursor(0,1); Serial.println(HH); if (HH < 10) { lcd.print('0'); } lcd.print(HH); lcd.print(":"); long int MM = (j - (HH*3600))/60 ; //converting the remaining time into remaining minutes lcd.setCursor(3,1); Serial.println(MM); if (MM < 10) { lcd.print('0'); } lcd.print(MM); lcd.print(":"); long int SS = j - ((HH*3600)+(MM*60)); //converting the remaining time into remaining seconds lcd.setCursor(6,1); Serial.println(SS); if (SS < 10) { lcd.print('0'); } lcd.print(SS); lcd.setCursor(9,1); lcd.print("cycle "); lcd.print(cycle); delay(1000); if (digitalRead(A2)==0){break;} if (j == 0) { // 1,10,12,13 open lcd.clear(); lcd.setCursor(0,0); lcd.print("Tens Timer Beep"); lcd.setCursor(1,1); lcd.print("End P1 cycle "); lcd.print(cycle); for(int k =0; k<= 200; k++) //this for loop is used for the buzzer to beep 200 time as the timer reaches zero { // 1,10,12,13,14 open digitalWrite(A4,HIGH); delay(300); digitalWrite(A4,LOW); delay(300); if (digitalRead(A1)==0){break;} } // 14 close 1,10,12,13 open } // 13 close 1,10,12 open } // 12 close 1,10 open cycle++; } // 10 close 1 open } // 1 close