Press Key "OK" to delete Display

Hey i hope somebody can help me with my problem :slight_smile:

Date and time shows correctly on the miacs lcd display, but i want to use the arrow buttons

on the miac to change the date and time and afterwards when pressing the OK button ‚Äúsave‚ÄĚ the date and time and delete it (line 0.0 and line 0.1) from the display ‚Äď i cant figured that out :confused:

I hope someone can give me an explanation and maybe a sulotion to my problem :slight_smile:
Please see the attached codes;

UrSetUp.zip (1.49 KB)

Just to try to understand what you want to do:

You see a data and a time on lines 0 and 1 on your display. You want to navigate through the displayed characters using the arrow keys and select one. You want to be able to change the selected character somehow (maybe using the up arrow to increment a number and the down arrow to decrement it etc.) Once you have finished updating the characters visible in the display, you want to press OK to store the new values of data and time and then delete the contents of the display.

Is that it ?

Tip: post the 2 files contained in your zip file directly in a post here. Use code tags. Then people using phones, tablets etc. can also see these.

Hello 6v6gt

Thank you for reading your post.
That’s right you read the middle post.
Have a suggestion for middle posts?

#include <font610.h>
#include <miac.h>
#include "Arduino.h"
miac miac;

float month;
float year;

char theDate[8];
char theTime[8];
char buffer[4];
uint8_t selection = 0;
int key;

int ok(){
  miac.clear();    
}

void setup()
{
  Serial.begin(9600);
  // setup the initial pointer
  drawCursor();
}

void clearCursor(void)
{
  moveCursor();
  miac.print(' ');
}

void left()
{
  
  if (selection > 0)
  {
    clearCursor();
    --selection;
    drawCursor();
    
  }
}

void right()
{
  if (selection < 11)
  {
    clearCursor();
    ++selection;
    drawCursor();
  }
}

void drawCursor(void)
{
  moveCursor();
  miac.print('^');
}

void moveCursor(void)
{
  switch (selection)
  {
    case 0: miac.cursor(0, 2); break;
    case 1: miac.cursor(1, 2); break;
    case 2: miac.cursor(3, 2); break;
    case 3: miac.cursor(4, 2); break;
    case 4: miac.cursor(6, 2); break;
    case 5: miac.cursor(7, 2); break;
    case 6: miac.cursor(10, 2); break;
    case 7: miac.cursor(11, 2); break;
    case 8: miac.cursor(13, 2); break;
    case 9: miac.cursor(14, 2); break;
    case 10: miac.cursor(16, 2); break;
    case 11: miac.cursor(17, 2); break;
  }
}


void incTime(char *data, uint8_t max)
{
  if (*data < (max + '0'))
  {
    *data += 1;
    miac.timeWrite(theTime);
  }
}

void decTime(char *data)
{
  if (*data > '0')
  {
    *data -= 1;
    miac.timeWrite(theTime);
  }
}

void incDate(char *data, uint8_t max)
{
  if (*data < (max + '0'))
  {
    *data += 1;
    miac.dateWrite(theDate);
  }
}

void decDate(char *data)
{
  if (*data > '0')
  {
    *data -= 1;
    miac.dateWrite(theDate);
  }
}

void up()
{
  switch (selection)
  {
    case 0: incDate(&theDate[0], 3); break;
    case 1: incDate(&theDate[1], 9); break;
    case 2: incDate(&theDate[2], 1); break;
    case 3: incDate(&theDate[3], 9); break;
    case 4: incDate(&theDate[4], 9); break;
    case 5: incDate(&theDate[5], 9); break;
    case 6: incTime(&theTime[0], 2); break;
    case 7: incTime(&theTime[1], 9); break;
    case 8: incTime(&theTime[2], 5); break;
    case 9: incTime(&theTime[3], 9); break;
    case 10: incTime(&theTime[4], 5); break;
    case 11: incTime(&theTime[5], 9); break;
  }
}

void down()
{
  switch (selection)
  {
    case 0: decDate(&theDate[0]); break;
    case 1: decDate(&theDate[1]); break;
    case 2: decDate(&theDate[2]); break;
    case 3: decDate(&theDate[3]); break;
    case 4: decDate(&theDate[4]); break;
    case 5: decDate(&theDate[5]); break;
    case 6: decTime(&theTime[0]); break;
    case 7: decTime(&theTime[1]); break;
    case 8: decTime(&theTime[2]); break;
    case 9: decTime(&theTime[3]); break;
    case 10: decTime(&theTime[4]); break;
    case 11: decTime(&theTime[5]); break;
  }
}


void loop()
{
  delay(50); // wait a while
 
  // print the date DD/MM/YY ¨
  buffer[0] = theDate[0];
  buffer[1] = theDate[1];
  buffer[2] = '\0';
  float day = atof(buffer);//convert the array into a float

  buffer[0] = theDate[2];
  buffer[1] = theDate[3];
  buffer[2] = '\0';
  //month = atoi(buffer);
  float month = atof(buffer);

  buffer[0] = theDate[4];
  buffer[1] = theDate[5];
  buffer[2] = '\0';
  //year = atoi(buffer);
  float year = atof(buffer);
 
  key = miac.keypadRead();
  switch (key) {
    case 1: left(); break;
    case 3: down(); break;
    case 4: ok(); break;
    case 5: up(); break;
    case 7: right(); break;
    }
    
//If (key = 4) then delete below!

 miac.dateRead(theDate);
 miac.cursor(0, 1);
  //print the date DD/MM/YY
  miac.print(theDate[0]);
  miac.print(theDate[1]);
  miac.print(':');

  miac.print(theDate[2]);
  miac.print(theDate[3]);
  miac.print(':');

  miac.print("20");
  miac.print(theDate[4]);
  miac.print(theDate[5]);
  Serial.println(key);

}

UrSetUp.zip (1.08 KB)

Most people here will ‚Äėnot‚Äô open a ZIP file.

Use CTRL T to format the sketch. Please use code tags. Use the </> icon in the posting menu. [code] Paste sketch here. [/code].

.

I don't know the MIAC device, but looking at a picture of it, it is an Arduino compatible industrial control device with an LCD display and, relevant to your task, 5 buttons: UpArrow, DownArrow, LeftArrow, RightArrow, and OK.

Anyway, assuming that you want to develop software to change the date/time through the display by means of the available buttons, you have to first decide a few things:

  1. How are you going to force the program into time/date setting mode ? Maybe pressing the right and left arrow simultaneously.
  2. How are you going to confirm that the time the user has set in the display should be accepted as the new time ? probably with the OK button.
  3. How are you going to clean out an abandoned attempt to set the time ? Maybe a timeout if there has been no button press for 30 seconds.

The programming itself is not trivial but could be something like this:

  1. Detect a request to enter time setting mode.
  2. Move current date and time into a buffer representing the display. If no date / time is currently set, move a standard date time into the buffer or maybe even DDMMYY HHMM so the format is clear to the operator.
  3. Set up a continuous refresh of the display from the display buffer, blinking the currently active character.
  4. set up a continuous check for key presses right / left selects the next active character. up / down increments/ decrements the current character in the buffer OK forces a validation of the date/time in the buffer entered by the operator, copies the date / time from the buffer to the system date / time, clears the display and exits time setting mode.
  5. While in time setting mode, check for pauses in the key presses of longer than 30 seconds and, if one, exit programming mode.

Since the code you have developed is quite complex, I can't look at in more detail until you get to the stage of having a specific question about it.

Hello 6v6gt Many, many thanks for your description and detailed instructions: I will immediately go thorough codes through according to your instructions.

Many, many thanks

Good weekend