Previous functions repeated with reception of certain signals.

Hi guys,

An interested in finding a way that I can do repletion of a previously called function when the signals of the infrared remote are received. Any moment I hold a button of my infrared remote, it gives out hex digits of F only. Currently am trying to do a program writeup that if my device will receive the F’s again, it can be able to do a repetition of the previously ran function. https://www.theengineeringprojects.com/2021/10/data-types-variables-and-operators-in-c.html

This program am doing for my small osoyoo kit of my car.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*

enum DN

GO_REPEAT,
DEF
Drive_Num=DEF;


void go_Advance(void) //Forward
{
digitalWrite(RightDirectPin1,LOW);
digitalWrite(RightDirectPin2,HIGH);
digitalWrite(LeftDirectPin1,LOW);
digitalWrite(LeftDirectPin2,HIGH);
analogWrite(speedPinL,100);
analogWrite(speedPinR,100);
}

void do_Drive_Tick()
{
switch (Drive_Num)
{
case GO_REPEAT://Need code here to repeat previous function (in this case it was GO_ADVANCE)
case GO_ADVANCE:go_Advance();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;
case GO_LEFT: go_Left();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;
default:break;




*/

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
enum command { REPEAT, ADVANCE, LEFT, NOP /* etc. */ } ;

void do_tick( command cmd )
{
    static command last_processed_command = NOP ; // remember the last processed command

    if( cmd == REPEAT ) return do_tick(last_processed_command) ; // repeat the last processed command

    // else
    last_processed_command = cmd ; // update last processed command

    switch(cmd) // switch on command, do whatever
    {
        case ADVANCE : go_advance() ; /* ... */ break ;
        
        // etc.
    }
}
Topic archived. No new replies allowed.