Timing DC Motor with 'millis' // motor driver, capacitiv touch tft. [SOLVED]

Mainproblem (code line 120-149)):

  1. How to implement a ‘millis (B)’ timed switching (clockwise (10sek)–>pause(1sek)-- >
    anticlockwise rotation10sek) inside a millis (A 8 Minutes) timed overall process?

  2. i have a subsequent motor timing event with a different duration and i guess i will run into
    trouble keeping them seperate the way i tried to solve it

–>Displayed code is not functional, attached code works

Hello everyone. I am working on my first sketch (Film Development ‘Processor’) and cant really figure out how to do it. I have copied code from different tutorials. Not sure if to mention the source?

I have a dc motor on a H-Bridge driver. The spin direction (clockwise/anti clockwise) is controlled by either Pin [8 high / 7 low] or [8 low / 7 high]. Motor is stopped by Pin [8 high / 7 high]. Speed is controlled by PWM on Pin 3.

In addition i have a tft touchshield (Adfruit/GFX library).

I wrote a simple menu:

  1. Homescreen: select between 4 different Programs (LAB, B&W, C41, E6)
    –>Lets say we want to develop Black and White negatives: We press the BW Button
  2. B&W Screen: here we see the variables Development Time and Rotation speed
    –>we hit the start button and the dc motor is started in 1 (one) direction. The duration is timed by
    millis function.
    –>During movement of the motor i have the obtion to abort turning and getting back to the
    homescreen and setting the motor off by setting [8 high / 7 high]
  3. Watering
    → if the time of the development is elapsed i come to a new screen instructing to water the film
    –>after hitting ok a new screen is shown

in the code there are more pages and more stuff i need to work on, but for the time beeing its not as critical.

little extra problem:
The Motor is started by an ‘if’ instruction (reading the finger press position), then a function (makeBWRotation) is executed and timed by ‘millis’. Since the button press only happens once (starting the motor) the 'milli evaluation can not happend inside the ‘if’ where the function is called (code line 120-149). So i decided to move the millis check outside the if function.
After the Time of rotation is elapsed, a new page is drawn, initiate by the previous millis evaluation. To avoid the loop flickering i put it into a new ‘if’ to just work when the current page number is a certain one. But since the loop is continuesly running so are also the previously stated page numbers for identification, constantly changing and the same finger press position on page A does something different on page B.

Any Idea, whats the proper way to do that?

#include "Adafruit_GFX.h"               // Grafic lib
#include "SPI.h"                        // this is needed for display
#include "Wire.h"                       // this is needed for FT6206
#include "Adafruit_ILI9341.h"           // TFT chip 
#include "Adafruit_FT6206.h"            //capaitive touch controller
#include "Fonts/FreeMonoBold12pt7b.h"   // font
#include "Fonts/FreeMonoBold18pt7b.h"   // font
//#include "Fonts/FreeMonoBold24pt7b.h"   // font
#include "Fonts/FreeMonoBold9pt7b.h"   // font

// define Pins for TFT data/command select and chip select.
#define TFT_DC 9
#define TFT_CS 10

//TFT Use hardware SPI (on Uno, #13, #12, #11 or SPI Pins)
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//Touchscreen FT6206 uses hardware I2C (SCL/SDA, Pin 15/16)
Adafruit_FT6206 ts = Adafruit_FT6206();

const int pwm = 3 ;  //initializing pin 3 as pwm for DC Motor
const int in_1 = 8 ; // Pin 8 for high/low output to determined DC Motor direction
const int in_2 = 7 ; // Pin 7 for high/low output to determined DC Motor direction

unsigned long startMillisBWEnt;                   // when was action started: BW Entwicklung
unsigned long currentMillisBWEnt;                 // timestamp/time of 'Now':BW Entwicklung
float Entwicklungszeit = 0.1;                // in Minuten
const unsigned long BW_Entw_Time = Entwicklungszeit * 1000 * 60 ; //BW Entwicklungszeit in Minuten for millis fuction used

unsigned long startMillisBWFix;                   // when was action started: BW Entwicklung
unsigned long currentMillisBWFix;                 // timestamp/time of 'Now':BW Entwicklung
float Fixierzeit = 0.5;                // in Minuten
const unsigned long BW_Fix_Time = Fixierzeit * 1000 * 60 ;

//void serialEventRun() {}

char currentPage;
int pwmValueBW = 80;

//=======================================void Setup==============================================
//startup screen; in setup-just things what need to be done once
void setup()   // call function 'setup'
  //Motor  For providing logic to L298 IC to choose the direction of the DC motor
  pinMode(pwm, OUTPUT) ;  //DC Motor Pin 3 as PWM output-speedcontrol
  pinMode(in_1, OUTPUT) ; //Logic pins are also set as output
  pinMode(in_2, OUTPUT) ;

  // call serial port and with program begin open communication at 9700 baud
  tft.begin();          //start tft screen, 'begin' must be defined in tft driver

  if (!ts.begin()) {
    Serial.println("Unable to start touchscreen.");
  else {
    Serial.println("Touchscreen started.");

  currentPage = '0';  //indictes we are on homescreen


void loop()
  //Timer for BW Motor-needs to be outside of touchscreen statement and motor drive function because touch screen if is just 1 time true
  currentMillisBWEnt = millis();  //get the current "time" (actually the number of milliseconds since the program started)
  if (currentPage == '5') { //When we are on the 1. dev timer screen
    if (currentMillisBWEnt - startMillisBWEnt >= BW_Entw_Time) { //test whether the period has elapsed, start millis is set when motor function is executed
      digitalWrite(in_1, HIGH) ;
      digitalWrite(in_2, HIGH) ;
      currentPage = '8';

  // B&W Screen
  if (currentPage == '1') {
    if (ts.touched()) {
      TS_Point p = ts.getPoint();
      p.x = map (p.x, 0, 240, 240, 0);
      p.y = map (p.y, 0, 320, 320, 0);
      int y = tft.height() - p.x;
      int x = p.y;

      // If we press the Start Button on BW screen
      if ((x >= 20) && (x <= 300) && (y >= 160) && (y <= 230)) {
        startMillisBWEnt = millis();  //initial start time
        drawTimerBWPage(); // open pop up page with count down timer and signal sound
        currentPage = '5' ;


  // Timer BW Page 1 current Page 5// Fixierungszeit Timer currentPage = '7'
  if (currentPage == '5' || '7') {
    if (ts.touched()) {
      TS_Point p = ts.getPoint();
      p.x = map (p.x, 0, 240, 240, 0);
      p.y = map (p.y, 0, 320, 320, 0);
      int y = tft.height() - p.x;
      int x = p.y;

      // If we press the Abbruch on TimerBWPage/Timer Fixierungszeit
      if ((x >= 20) && (x <= 300) && (y >= 160) && (y <= 230)) {
        drawBWPage ();
        currentPage = '1' ;


Processor_T.ino (19.7 KB)

Hello all. Topic is solved. Can be closed.

code attached for everyone in need



Hello all. Topic is solved. Can be closed.

code attached for everyone in need



Glad to hear it. Please edit the topic and include [SOLVED] in the title to help others out