Help to my M2TKLIB project.

Hi
Can anyone help me with my program?

I Uses M2tklib. And have some things i'cant make.

In this code i like to make a screen that shows a countdown between picture take and to the new one is taken. Also a total count taken to now. And a button to come back to the main menu.

i think it is to go into then places with the comment in this.

void fn_start(m2_el_fnarg_p fnarg) {
  //
  // Here i like to have a loop to i puss the select button to end it.
  //
  Serial.println("Start"); 
  Serial.print("Delay = ");
  Serial.print(n_time_delay);
  Serial.print(" - TimeUnit = ");
  if (select_time_unit == 0) {  
    Serial.println("Minutter"); 
  };
  if (select_time_unit == 1) {
    Serial.println("Timer"); 
  };
  for(uint8_t a = n_time_delay; a > 0; a--){
    //
    // Here i like to have a emty screen there shows a countdown to the picture is taken and how many pictures there is taken to now.
    //
    n_time_delay_show = a;
    delay((1000*n_time_delay)*((select_time_unit*60)+1));
    Serial.print("a = ");
    Serial.println(a);
    takePic();
  }
  //
  // Loop end
  //
  Serial.println("Slut"); 
}

Full code, the full loop is not made yet.

/*

  CanonTimeTake.pde
  Arduino Nano Canon time take.
  Version 2
  Build 1

  Unit to control Canon 1200D picture take.
  Uses:
  Arduino Nano V3.
  OLED from aliexpress with SPI interface, Software SPI
  Rotery encoder with key.
  
  Universal 8bit Graphics Library, https://github.com/olikraus/u8glib/
  Mini Interative Interface Toolkit Library, https://code.google.com/p/m2tklib/

  Key Rotater
    Pin 1 -   D2
    Pin 2 -   D3
    Select    D12

  Cam
    Focus   D10
    Trigger   D11

  Display
    SCL   D4
    SDA   D5
    RST   D7
    O/C   D6  
 
*/

#include "U8glib.h"
#include "M2tk.h"
#include "utility/m2ghu8g.h"

// setup u8g object, please remove comment from one of the following constructor calls
// IMPORTANT NOTE: The following list is incomplete. The complete list of supported 
U8GLIB_SSD1306_128X64 u8g(4, 5, 8, 6, 7);  
// SW SPI Com: SCK = 3, MOSI = 4, CS = 7, D/C = 5, RST = 6 
// Nano  OLED
// D4    SCL
// D5    SDA
// D8    brues ikke
// D6    D/C
// D7    RST

int ledFocus   = 11;
int ledTrigger = 10;

uint32_t n_total_pic = 0;
uint8_t n_time_delay = 10;
uint8_t select_time_unit = 0;

void takePic() {
  digitalWrite(ledFocus, HIGH);
  delay(1000);
  digitalWrite(ledFocus, LOW);
  delay(100);
  digitalWrite(ledTrigger, HIGH);
  delay(1000);
  digitalWrite(ledTrigger, LOW);
  n_total_pic++;
}



const char *fn_idx_to_time_unit(uint8_t idx)
{
  if( idx == 0) return "Minutter";
  else return "Timer";
}

uint8_t n_time_delay_show = n_time_delay;

void fn_start(m2_el_fnarg_p fnarg) {
  //
  // Here i like to have a loop to i puss the select button to end it.
  //
  Serial.println("Start"); 
  Serial.print("Delay = ");
  Serial.print(n_time_delay);
  Serial.print(" - TimeUnit = ");
  if (select_time_unit == 0) {  
    Serial.println("Minutter"); 
  };
  if (select_time_unit == 1) {
    Serial.println("Timer"); 
  };
  for(uint8_t a = n_time_delay; a > 0; a--){
    //
    // Here i like to have a emty screen there shows a countdown to the picture is taken and how many pictures there is taken to now.
    // And a button to press to stop the loop. And then go back to the mainmenu.
    //
    n_time_delay_show = a;
    delay((1000*n_time_delay)*((select_time_unit*60)+1));
    Serial.print("a = ");
    Serial.println(a);
    takePic();
  }
  //
  // Loop end
  //
  Serial.println("Slut"); 
}


void fn_take(m2_el_fnarg_p fnarg) {
  takePic();
}


//=================================================
// Forward declaration of the toplevel element
M2_EXTERN_ALIGN(top_menu);

//=================================================

M2_LABEL(el_l1, "f1", "Canon Timer");
M2_LABEL(el_u1, NULL, " V2.1!");
M2_LABEL(el_l2, "f1", " Tid :");
M2_U8NUM(el_u2, "c2", 0, 60, &n_time_delay);


M2_LABEL(el_l3, "f1", " Enhed :");
M2_COMBO(el_u3, NULL, &select_time_unit, 2, fn_idx_to_time_unit);
M2_BUTTON(el_fn_start, "f1x0y50", "[Start]", fn_start);
M2_BUTTON(el_fn_take, "f1b1x30y50", "[Take]", fn_take);
M2_LABEL(el_l5, "f1", "Count :");
M2_U32NUM(el_u5, "c4r1", &n_total_pic);

M2_LIST(list) = { &el_l1, &el_u1, &el_l2, &el_u2, &el_l3, &el_u3, &el_fn_start, &el_fn_take, &el_l5, &el_u5 };
M2_GRIDLIST(el_gridlist, "c2", list);
M2_ALIGN(top_menu, "-1|1W64H64", &el_gridlist);

// m2 object and constructor
// Note: Use the "m2_eh_4bd" handler, which fits better to the "m2_es_arduino_rotary_encoder" 
M2tk m2(&top_menu, m2_es_arduino_rotary_encoder, m2_eh_4bd, m2_gh_u8g_bf);

//=================================================
// Arduino Setup & Loop

void setup(void) {
    pinMode(ledFocus, OUTPUT);
    pinMode(ledTrigger, OUTPUT);
    digitalWrite(ledFocus, LOW);
    digitalWrite(ledTrigger, LOW);
    
  // Connect u8glib with m2tklib
  m2_SetU8g(u8g.getU8g(), m2_u8g_box_icon);

  // Assign u8g font to index 0
  m2.setFont(0, u8g_font_6x12r);
  m2.setFont(1, u8g_font_7x13r);
  

  // define button for the select message
  m2.setPin(M2_KEY_SELECT, 12);        
  
  // The incremental rotary encoder is conected to these two pins
  m2.setPin(M2_KEY_ROT_ENC_A, 3);
  m2.setPin(M2_KEY_ROT_ENC_B, 2);

  Serial.begin(9600);
}

void loop() {
  // check rotary encoder also inside the picture loop
  m2.checkKey();  
  // process events and redraw menu if required
  if ( m2.handleKey() != 0 ) {
    u8g.firstPage();  
    do {
      // check rotary encoder also inside the picture loop
      m2.checkKey();
      // draw menu
      m2.draw();
    } while( u8g.nextPage() );
  }
}

Hope sombody can help me, and sorry for my english.

Any help please??

Can't anybody help me at all.

Hi

You can just use the native u8glib commands to write the countdown on the screen. Of course you need the picture-loop inside your

 for(uint8_t a = n_time_delay; a > 0; a--)

loop

At the end, call m2.draw(); to render the m2tk content.

Oliver