BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

String input, for my medical box

#1

i want to build a medical box, that will open automaticly, user input times to eat medicine( one time, two time and three 3) in 6 six string input that related to the six box, i have done to read the input from terminal input and have finished to save the input user and not error when the aplication run (figure 1, and program 1), but i have error when i want to use the input to control to open the box and in the function program. in void program(), i want use the input to open box one by one, with step : 1. check the input box, for example input box 1 is 3 so it jump(switch 3) and run the case: 3 check the button that indicate if the fill of the box have put by user, check the timer and if have done so jump to check box 2 and check the input and do the same case, and then check box 3… and until box 6. thanks you.

 * Project: string inpu untuk mengtur jam minum obat
 * tanggal: 4/7/2019
 * nama   : Indrawan Arifianto
 */

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

//Widget yang digunakan
BlynkTimer timer;
WidgetRTC rtc;
WidgetLED led1(V4);

// You should get Auth Token in the Blynk App.
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "**************************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "********************************";
char pass[] = "*******************************";

// Attach virtual serial Pil_1 to Virtual Pin V1
WidgetTerminal terminal(V11);
WidgetTerminal Pil_1(V5);
WidgetTerminal Pil_2(V6);
WidgetTerminal Pil_3(V7);
WidgetTerminal Pil_4(V8);
WidgetTerminal Pil_5(V9);
WidgetTerminal Pil_6(V10);

//count untuk timer
unsigned count = 0;

//Save input on array
int SaveArray[8];
int nilai[5];
int button[2];

// You can send commands from Pil_1 to your hardware. Just use
// the same Virtual Pin as your Pil_1 Widget
BLYNK_WRITE(V5)
{
  if (String("1") == param.asStr()) {
    Pil_1.println("Minum 1x1");
    SaveArray[1]=1;
    Serial.println("Kotak obat 1: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_1.println("Minum 2x1");
    SaveArray[1]=2;
    Serial.println("Kotak obat 1: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_1.println("Minum 3x1");
    SaveArray[1]=3;
    Serial.println("Kotak obat 1: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_1.println("Minum 4x1");
    SaveArray[1]=4;
    Serial.println("Kotak obat 1: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_1.println("Minum 5x1");
    Serial.println("Kotak obat 1: Minum 5x1");
    SaveArray[1]=5;
  } else {
    // Send it back
    Pil_1.print("You said:");
    Pil_1.write(param.getBuffer(), param.getLength());
    Pil_1.println("Fix your Time input") ;
    Pil_1.println();
  }
  // Ensure everything is sent
  Pil_1.flush();
}


// You can send commands from Pil_1 to your hardware. Just use
// the same Virtual Pin as your Pil_1 Widget
BLYNK_WRITE(V6)
{
  if (String("1") == param.asStr()) {
    Pil_2.println("Minum 1x1");
    SaveArray[2]=1;
    Serial.println("Kotak obat 2: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_2.println("Minum 2x1");
    SaveArray[2]=2;
    Serial.println("Kotak obat 2: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_2.println("Minum 3x1");
    SaveArray[2]=3;
    Serial.println("Kotak obat 2: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_2.println("Minum 4x1");
    SaveArray[2]=4;
    Serial.println("Kotak obat 2: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_2.println("Minum 5x1");
    SaveArray[2]=5;
    Serial.println("Kotak obat 2: Minum 5x1");
  } else {
    // Send it back
    Pil_2.print("You said:");
    Pil_2.write(param.getBuffer(), param.getLength());
    Pil_2.println("Fix your Time input") ;
    Pil_2.println();
  }
  // Ensure everything is sent
  Pil_2.flush();
}


// You can send commands from Pil_1 to your hardware. Just use
// the same Virtual Pin as your Pil_1 Widget
BLYNK_WRITE(V7)
{
  if (String("1") == param.asStr()) {
    Pil_3.println("Minum 1x1");
    SaveArray[3]=1;
    Serial.println("Kotak obat 3: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_3.println("Minum 2x1");
    SaveArray[3]=2;
    Serial.println("Kotak obat 3: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_3.println("Minum 3x1");
    SaveArray[3]=3;
    Serial.println("Kotak obat 3: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_3.println("Minum 4x1");
    SaveArray[3]=4;
    Serial.println("Kotak obat 3: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_3.println("Minum 5x1");
    SaveArray[3]=5;
    Serial.println("Kotak obat 3: Minum 5x1");
  } else {
    // Send it back
    Pil_3.print("You said:");
    Pil_3.write(param.getBuffer(), param.getLength());
    Pil_3.println("Fix your Time input") ;
    Pil_3.println();
  }
  // Ensure everything is sent
  Pil_3.flush();
}


// You can send commands from Pil_4 to your hardware. Just use
// the same Virtual Pin as your Pil_3 Widget
BLYNK_WRITE(V8)
{
  if (String("1") == param.asStr()) {
    Pil_4.println("Minum 1x1");
    SaveArray[4]=1;
    Serial.println("Kotak obat 4: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_4.println("Minum 2x1") ;
    SaveArray[4]=2;
    Serial.println("Kotak obat 4: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_4.println("Minum 3x1");
    SaveArray[4]=3;
    Serial.println("Kotak obat 4: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_4.println("Minum 4x1") ;
    SaveArray[4]=4;
    Serial.println("Kotak obat 4: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_4.println("Minum 5x1") ;
    SaveArray[4]=5;
    Serial.println("Kotak obat 4: Minum 5x1");
  } else {
    // Send it back
    Pil_4.print("You said:");
    Pil_4.write(param.getBuffer(), param.getLength());
    Pil_4.println("Fix your Time input") ;
    Pil_4.println();
  }
  // Ensure everything is sent
  Pil_4.flush();
}


// You can send commands from Pil_5 to your hardware. Just use
// the same Virtual Pin as your Pil_5 Widget
BLYNK_WRITE(V9)
{
  if (String("1") == param.asStr()) {
    Pil_5.println("Minum 1x1") ;
    SaveArray[5]=1;
    Serial.println("Kotak obat 5: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_5.println("Minum 2x1") ;
    SaveArray[5]=2;
    Serial.println("Kotak obat 5: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_5.println("Minum 3x1") ;
    SaveArray[5]=3;
    Serial.println("Kotak obat 5: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_5.println("Minum 4x1") ;
    SaveArray[5]=4;
    Serial.println("Kotak obat 5: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_5.println("Minum 5x1") ;
    SaveArray[5]=5;
    Serial.println("Kotak obat 5: Minum 5x1");
  } else {
    // Send it back
    Pil_5.print("You said:");
    Pil_5.write(param.getBuffer(), param.getLength());
    Pil_5.println("Fix your Time input") ;
    Pil_5.println();
  }
  // Ensure everything is sent
  Pil_5.flush();
}



// You can send commands from Pil_5 to your hardware. Just use
// the same Virtual Pin as your Pil_5 Widget
BLYNK_WRITE(V10)
{
  if (String("1") == param.asStr()) {
    Pil_6.println("Minum 1x1") ;
    SaveArray[6]=1;
    Serial.println("Kotak obat 6: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_6.println("Minum 2x1") ;
    SaveArray[6]=2;
    Serial.println("Kotak obat 6: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_6.println("Minum 3x1") ;
    SaveArray[6]=3;
    Serial.println("Kotak obat 6: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_6.println("Minum 4x1") ;
    SaveArray[6]=4;
    Serial.println("Kotak obat 6: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_6.println("Minum 5x1") ;
    SaveArray[6]=5;
    Serial.println("Kotak obat 6: Minum 5x1");
  } else {
    // Send it back
    Pil_6.print("You said:");
    Pil_6.write(param.getBuffer(), param.getLength());
    Pil_6.println("Fix your Time input") ;
    Pil_6.println();
  }
  // Ensure everything is sent
  Pil_6.flush();
}

//debug dengan push button virtual port 12
BLYNK_WRITE(V12) 
{
  if(param.asInt()==HIGH)
  {
    Serial.println("button on");
    button[1]=1;
  }else
  {
    Serial.println("button off");
    button[1]=0;
  } 
}



// Digital clock display of the time
void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();

  // Send time to the App
  Blynk.virtualWrite(V1, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V2, currentDate);
}


BLYNK_CONNECTED() {
  // Synchronize time on connection
  rtc.begin();
}


void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  // Clear the Pil_6 content
  Pil_1.clear();
  Pil_2.clear();
  Pil_3.clear();
  Pil_4.clear();
  Pil_5.clear();
  Pil_6.clear();
  

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(F("Type time one until 5 and get a reply, or type"));
  terminal.println(F("anything else and get it printed back."));
  terminal.flush();

  setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)

  // Display digital clock every 10 seconds
  timer.setInterval(1000L, clockDisplay);
}

void loop()
{
  Blynk.run();
  timer.run();
  CekOutput();
}

and it’s run correctly(picture 1) but when i want to use the input program i have a trouble blynk is disconnected and stop working (complete program) i add function void program

 * Project: string inpu untuk mengtur jam minum obat
 * tanggal: 4/7/2019
 * nama   : Indrawan Arifianto
 */

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

//Widget yang digunakan
BlynkTimer timer;
WidgetRTC rtc;
WidgetLED led1(V4);

// You should get Auth Token in the Blynk App.
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***************************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "**************************";
char pass[] = "*************************";

// Attach virtual serial Pil_1 to Virtual Pin V1
WidgetTerminal terminal(V11);
WidgetTerminal Pil_1(V5);
WidgetTerminal Pil_2(V6);
WidgetTerminal Pil_3(V7);
WidgetTerminal Pil_4(V8);
WidgetTerminal Pil_5(V9);
WidgetTerminal Pil_6(V10);

//count untuk timer
unsigned count = 0;

//Save input on array
int SaveArray[8];
int nilai[5];
int button[2];

// You can send commands from Pil_1 to your hardware. Just use
// the same Virtual Pin as your Pil_1 Widget
BLYNK_WRITE(V5)
{
  if (String("1") == param.asStr()) {
    Pil_1.println("Minum 1x1");
    SaveArray[1]=1;
    Serial.println("Kotak obat 1: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_1.println("Minum 2x1");
    SaveArray[1]=2;
    Serial.println("Kotak obat 1: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_1.println("Minum 3x1");
    SaveArray[1]=3;
    Serial.println("Kotak obat 1: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_1.println("Minum 4x1");
    SaveArray[1]=4;
    Serial.println("Kotak obat 1: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_1.println("Minum 5x1");
    Serial.println("Kotak obat 1: Minum 5x1");
    SaveArray[1]=5;
  } else {
    // Send it back
    Pil_1.print("You said:");
    Pil_1.write(param.getBuffer(), param.getLength());
    Pil_1.println("Fix your Time input") ;
    Pil_1.println();
  }
  // Ensure everything is sent
  Pil_1.flush();
}


// You can send commands from Pil_1 to your hardware. Just use
// the same Virtual Pin as your Pil_1 Widget
BLYNK_WRITE(V6)
{
  if (String("1") == param.asStr()) {
    Pil_2.println("Minum 1x1");
    SaveArray[2]=1;
    Serial.println("Kotak obat 2: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_2.println("Minum 2x1");
    SaveArray[2]=2;
    Serial.println("Kotak obat 2: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_2.println("Minum 3x1");
    SaveArray[2]=3;
    Serial.println("Kotak obat 2: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_2.println("Minum 4x1");
    SaveArray[2]=4;
    Serial.println("Kotak obat 2: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_2.println("Minum 5x1");
    SaveArray[2]=5;
    Serial.println("Kotak obat 2: Minum 5x1");
  } else {
    // Send it back
    Pil_2.print("You said:");
    Pil_2.write(param.getBuffer(), param.getLength());
    Pil_2.println("Fix your Time input") ;
    Pil_2.println();
  }
  // Ensure everything is sent
  Pil_2.flush();
}


// You can send commands from Pil_1 to your hardware. Just use
// the same Virtual Pin as your Pil_1 Widget
BLYNK_WRITE(V7)
{
  if (String("1") == param.asStr()) {
    Pil_3.println("Minum 1x1");
    SaveArray[3]=1;
    Serial.println("Kotak obat 3: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_3.println("Minum 2x1");
    SaveArray[3]=2;
    Serial.println("Kotak obat 3: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_3.println("Minum 3x1");
    SaveArray[3]=3;
    Serial.println("Kotak obat 3: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_3.println("Minum 4x1");
    SaveArray[3]=4;
    Serial.println("Kotak obat 3: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_3.println("Minum 5x1");
    SaveArray[3]=5;
    Serial.println("Kotak obat 3: Minum 5x1");
  } else {
    // Send it back
    Pil_3.print("You said:");
    Pil_3.write(param.getBuffer(), param.getLength());
    Pil_3.println("Fix your Time input") ;
    Pil_3.println();
  }
  // Ensure everything is sent
  Pil_3.flush();
}


// You can send commands from Pil_4 to your hardware. Just use
// the same Virtual Pin as your Pil_3 Widget
BLYNK_WRITE(V8)
{
  if (String("1") == param.asStr()) {
    Pil_4.println("Minum 1x1");
    SaveArray[4]=1;
    Serial.println("Kotak obat 4: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_4.println("Minum 2x1") ;
    SaveArray[4]=2;
    Serial.println("Kotak obat 4: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_4.println("Minum 3x1");
    SaveArray[4]=3;
    Serial.println("Kotak obat 4: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_4.println("Minum 4x1") ;
    SaveArray[4]=4;
    Serial.println("Kotak obat 4: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_4.println("Minum 5x1") ;
    SaveArray[4]=5;
    Serial.println("Kotak obat 4: Minum 5x1");
  } else {
    // Send it back
    Pil_4.print("You said:");
    Pil_4.write(param.getBuffer(), param.getLength());
    Pil_4.println("Fix your Time input") ;
    Pil_4.println();
  }
  // Ensure everything is sent
  Pil_4.flush();
}


// You can send commands from Pil_5 to your hardware. Just use
// the same Virtual Pin as your Pil_5 Widget
BLYNK_WRITE(V9)
{
  if (String("1") == param.asStr()) {
    Pil_5.println("Minum 1x1") ;
    SaveArray[5]=1;
    Serial.println("Kotak obat 5: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_5.println("Minum 2x1") ;
    SaveArray[5]=2;
    Serial.println("Kotak obat 5: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_5.println("Minum 3x1") ;
    SaveArray[5]=3;
    Serial.println("Kotak obat 5: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_5.println("Minum 4x1") ;
    SaveArray[5]=4;
    Serial.println("Kotak obat 5: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_5.println("Minum 5x1") ;
    SaveArray[5]=5;
    Serial.println("Kotak obat 5: Minum 5x1");
  } else {
    // Send it back
    Pil_5.print("You said:");
    Pil_5.write(param.getBuffer(), param.getLength());
    Pil_5.println("Fix your Time input") ;
    Pil_5.println();
  }
  // Ensure everything is sent
  Pil_5.flush();
}



// You can send commands from Pil_5 to your hardware. Just use
// the same Virtual Pin as your Pil_5 Widget
BLYNK_WRITE(V10)
{
  if (String("1") == param.asStr()) {
    Pil_6.println("Minum 1x1") ;
    SaveArray[6]=1;
    Serial.println("Kotak obat 6: Minum 1x1");
  }
  
    else if (String("2") == param.asStr()) {
    Pil_6.println("Minum 2x1") ;
    SaveArray[6]=2;
    Serial.println("Kotak obat 6: Minum 2x1");
  }
  
    else if (String("3") == param.asStr()) {
    Pil_6.println("Minum 3x1") ;
    SaveArray[6]=3;
    Serial.println("Kotak obat 6: Minum 3x1");
  }
  
    else if (String("4") == param.asStr()) {
    Pil_6.println("Minum 4x1") ;
    SaveArray[6]=4;
    Serial.println("Kotak obat 6: Minum 4x1");
  }

    else if (String("5") == param.asStr()) {
    Pil_6.println("Minum 5x1") ;
    SaveArray[6]=5;
    Serial.println("Kotak obat 6: Minum 5x1");
  } else {
    // Send it back
    Pil_6.print("You said:");
    Pil_6.write(param.getBuffer(), param.getLength());
    Pil_6.println("Fix your Time input") ;
    Pil_6.println();
  }
  // Ensure everything is sent
  Pil_6.flush();
}

//debug dengan push button virtual port 12
BLYNK_WRITE(V12) 
{
  if(param.asInt()==HIGH)
  {
    Serial.println("button on");
    button[1]=1;
  }else
  {
    Serial.println("button off");
    button[1]=0;
  } 
}



// Digital clock display of the time
void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();

  // Send time to the App
  Blynk.virtualWrite(V1, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V2, currentDate);
}


BLYNK_CONNECTED() {
  // Synchronize time on connection
  rtc.begin();
}


void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  // Clear the Pil_6 content
  Pil_1.clear();
  Pil_2.clear();
  Pil_3.clear();
  Pil_4.clear();
  Pil_5.clear();
  Pil_6.clear();
  

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(F("Type time one until 5 and get a reply, or type"));
  terminal.println(F("anything else and get it printed back."));
  terminal.flush();

  setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)

  // Display digital clock every 10 seconds
  timer.setInterval(1000L, clockDisplay);
}

void loop()
{
  Blynk.run();
  timer.run();
  Program();
  CekOutput();
}


void CekOutput()
{
  for(int i=1;i<=6;i++)
  {
    Serial.print("Nilai di pil ");Serial.print(i);Serial.print(" :");Serial.println(SaveArray[i]);
  }
    Serial.println("");Serial.println("");Serial.println("");
    delay(1000);
}*/

void Program()
{ 
 // int i=3;
  for(int i=1;i<=6;i++)
  {  
    //simpan nilai SaveArray pada Variable nilai
    nilai[i]=SaveArray[i];
    Serial.print("Cek Kotak ke-");Serial.println(i);
    delay(1000);
    
    //Program Switch untuk membandingkan nilai waktu
    switch (nilai[i]) {
    case 1:
    //minum 1 kali
    Serial.println("Minum obat 1 kali");
    
    //while(Berat(n+1) == Berat(n))//cek obat sudah diambil atau belum
    if(button[1] == 0)//cek obat sudah diambil atau belum
    {
        if(hour()==16)
        {
          if(second()==2)//ketika jam 6 lebih 2 detik
          {
          //nyalakan Buzzer
          Serial.println("Nyalakan Buzzer");
          //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
          //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

          //fungsi gerakkan stepper
          Serial.print("putar Stepper ke kotak ");Serial.println(i);
          //stepper.setSpeed(4); // gerakkan Stepper dengan kecepatan 4 rpm
          //stepper.step(255); // buka kotak (Lakukan 255 langkah)--sesuai dengan satu revolusi dalam satu menit
          }
          
          if(minute()==5)//menit ke 5
          {
           //nyalakan Buzzer
           Serial.println("Nyalakan Buzzer, peringatan 5 menit");
           //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
           //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik
          }        

          if(minute()==59)//menit ke 59
          {
           //nyalakan Buzzer
           Serial.println("Nyalakan Buzzer, peringatan 59 menit");
           //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
           //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

           //kirim email
           Serial.println("Kirim email notifikasi belum minum obat");
           delay(1000);
          }else{
           Serial.println("Jam Sesuai, tetapi bukan peringatan minute");
           delay(1000);
          }
                  
        }
        else{
          //Kotak_Close
          Serial.println("kotak close, Selain jam itu");
          delay(1000);
        }
      }else{
      //Cek nilai kotak berikutnya
      Serial.print("Cek nilai kotak ");Serial.println(i+1);
      delay(1000);
      //goto sini;
      }
      break;
      
    case 2:
      //minum 2 kali
      Serial.println("Minum obat 2 kali");
           
      //while(Berat(n+1) == Berat(n))//cek obat sudah diambil atau belum
      if(button[1] == 0)//cek obat sudah diambil atau belum
      {
        if(hour()==6 ||hour()==18)
        {
          if(second()==2)//ketika jam 6 lebih 2 detik
          {
          //nyalakan Buzzer
          Serial.println("Nyalakan Buzzer");
          //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
          //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

          //fungsi gerakkan stepper
          Serial.print("putar Stepper ke kotak ");Serial.println(i);
          //stepper.setSpeed(4); // gerakkan Stepper dengan kecepatan 4 rpm
          //stepper.step(255); // buka kotak (Lakukan 255 langkah)--sesuai dengan satu revolusi dalam satu menit
          }

          if(minute()==5)//menit ke 5
          {
           //nyalakan Buzzer
           Serial.println("Nyalakan Buzzer, peringatan 5 menit");
           //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
           //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik
          }        

          if(minute()==59)//menit ke 59
          {
           //nyalakan Buzzer
           Serial.println("Nyalakan Buzzer, peringatan 59 menit");
           //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
           //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

           //kirim email
           Serial.println("Kirim email notifikasi belum minum obat");
          }        
        }
        else{
          //Kotak_Close
          Serial.println("kotak close(else)");
        }
      }else{
      //Cek nilai kotak berikutnya
      Serial.print("Cek nilai kotak ");Serial.println(i+1);
      //goto sini;
      }
      break;
      
    case 3:
     //minum 3 kali
     Serial.println("Minum obat 3 kali");
     
     // while(Berat(n+1) == Berat(n))//cek obat sudah diambil atau belum
     if(button[1] == 0)//cek obat sudah diambil atau belum
     {
        if(hour()==6 || hour()==12 || hour()==18)
        {
          if(second()==2)//ketika jam 6 lebih 2 detik
          {
          //nyalakan Buzzer
          Serial.println("Nyalakan Buzzer");
          //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
          //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

          //fungsi gerakkan stepper
          Serial.print("putar Stepper ke kotak ");Serial.println(i);
          //stepper.setSpeed(4); // gerakkan Stepper dengan kecepatan 4 rpm
          //stepper.step(255); // buka kotak (Lakukan 255 langkah)--sesuai dengan satu revolusi dalam satu menit
          }

          if(minute()==5)//menit ke 5
          {
           //nyalakan Buzzer
           Serial.println("Nyalakan Buzzer, peringatan 40 menit");
           //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
           //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik
          }        

          if(minute()==59)//menit ke 59
          {
           //nyalakan Buzzer
           Serial.println("Nyalakan Buzzer, peringatan 59 menit");
           //digitalWrite(buzzer, HIGH);delay(10000); //nyalakan Buzzer 10 detik
           //digitalWrite(buzzer, LOW); //Matikan Buzzer 10 detik

           //kirim email
           Serial.println("Kirim email notifikasi belum minum obat");
          }        
        }
        else{
          //Kotak_Close
          Serial.println("kotak close(else)");
        }
      }else{
      //Cek nilai kotak berikutnya
      Serial.print("Cek nilai kotak ");Serial.println(i+1);
      //goto sini;
      }
      break;
       
    default:
      printf("Maaf, format nilai tidak sesuai \n");
      //goto sini;
      break;
   }
  
}
//goto sini;
}

when run program 1

stop working when i try compleate program

0 Likes

#2

You should read this:

Also, why not use one of the time widgets to input the times when each of the medication doses is required?

Pete.

1 Like

#3

at first I wanted to use the time input for each box, but I was confused to start. This tool should work by entering several time inputs, with a maximum of 4 input times in one day for one box. but i dont understand to use that, can you help me to give me a example? thanks you

0 Likes

#4

I think you’re on your own with that. Blynk provided the tools in the form of several time widgets and if you choose to use a custom solution then you’ll need to develop it yourself.

Have you sorted-out your void loop yet?

Pete.

0 Likes

#5

oh yes thank you sir, i have done to make a void loop() clean and have a good work. can you send me a reference to do some a input timer?

and work well.
image

0 Likes

#6

Posti g screenshot images of serial monitor output isn’t very helpful. Much better to copy and paste the information, with triple backticks so that it displays correctly.

Pete.

0 Likes