Timer and Counter

Hi
I am trying to find out, if it is possible to make a system based on Arduino.
I have not yet any specific knowledge of this system.
Function.
When a ON is pressed, a RED light must be ON
When a RUN function is pressed, a Timer 1 functions keeps the RED light ON for specified time, When time is finished, RED light goes to OFF and a Timer 2 starts. When Timer 2 finish, Timer 1 starts.
There must also be a Counter function, so the T1 and T2 function cn f.ex. run 10 times.
When the last timer function has ended, RED light must be ON, till RUN function is activated again.
Now the more special things.
Timer 1 and Timer 2 must easily have the option to change TIME. The same with the COUNTER.

I must have the possibility to turn the system ON = RED light
Then SET TIMER 1 (f.ex. 10 seconds) Then SET TIMER " (f.ex. 5 seconds). Then add f.ex 10 times to the COUNTER.
When I then press RUN, Timer 1 runs 10 seconds (RED ON), Timer 2 takes over and runs 5 seconds (RED OFF), then TIMER 1 ON 10 seconds (Light ON, then TIMER 2 ON 5 seconds (Light OFF) This continues 10 times, and ends with Light ON
Is that possible, including settings changeble, f.ex. at a Touch Screen, or other easy operated Items.
Sorry for my "bad English). I am from Denmark

Yes!

Def possible.

"Timer" and "Counter" have specific meanings in this context; don't get confused and think you have to wrangle the built in "peripherals" of the microprocessor. Timers and counters have their place, this project will not need either.

But timing and counting, for sure. This is fairly straightforward and depends mostly on the lengths of the times involved and how fast you need to count.

If it's a human pressing a button (or waving a keg, whatever) to move things along, the microprocessor will be totally under burdened and prolly spending most of its time waiting one the external world.

a7

Ensure your touchscreen uses a known, good, library. A library helps the Arduino talk to the Touchscreen. Knowing which library is correct seems to be the biggest problem with touchscreens.

(your English is very good. If you feel the need, write in your native language, and use a translation web site like translate.google.com)

look this over

const byte PinLed = 12;

enum { Off = HIGH, On = LOW };

unsigned long msecPeriod = 500;
unsigned      msecOn     = 500;
unsigned      msecOff    = 900;
unsigned long msec0;

int cnt = 0;
int state;

char s [90];

// -----------------------------------------------------------------------------
void
loop (void)
{
    // handle timing
    unsigned long msec = millis ();

    if (cnt && (msec - msec0) >= msecPeriod)  {
        state      = ! state;
        msecPeriod = state ? msecOff : msecOn;
        msec0      = msec;

        digitalWrite (PinLed, state);

        if (! state)
            cnt--;
    }

    // process cmds from serial monitor
    if (Serial.available ())  {
        char buf [90];
        int  n  = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
        buf [n] = '\0';

        Serial.println (buf);

        char cmd;
        int  val;
        sscanf (buf, "%c %d", &cmd, &val);

        switch (cmd) {
        case 'c':
            cnt        = val;
            msec0      = msec;
            msecPeriod = msecOn;
            state      = On;

            sprintf (s, " cnt = %d, msec = %lu", cnt, msec);
            Serial.println (s);
            break;

        case '1':
            msecOn = val;

            sprintf (s, " msecOn = %u", msecOn);
            Serial.println (s);
            break;

        case '2':
            msecOff = val;

            sprintf (s, " msecOff = %u", msecOff);
            Serial.println (s);
            break;
        }
    }
}

void
setup (void)
{
    Serial.begin (9600);

    pinMode (PinLed, OUTPUT);
    digitalWrite (PinLed, Off);

    msec0 = millis();
}

What timing accuracy ?

The project as described is fairly ‘simole’ to develop. unless there’s more you haven’t described,

Hi.
Thanks a lot.
Is this the programming so the functions are working ?
I will send this to my friend, who has a little programming skills and some parts as well.

Thanks again :slight_smile:

They are more expensive and significantly more complex to use for a beginner. I would consider a simple 16x2 LCD character screen and a few buttons, or maybe a rotary encoder.