Code implimentation

Dear all.

I need small logical implementation for this code.

I have 8 fault.below are order of fault.

F1-> First
F2->Sec
F3->3rd
F4->4th

In have shared part of it. below code working as mentioned
Latest fault F4 or 4th fault flicker 100% rate
PREV1 fault F3 or 3rd fault flicker 50% rate
PREV2fault F2 or2nd fault flicker steady
First fault F1 or1st fault flicker steady

but expected to work like this.
First fault F1 or 1st fault flicker 100%
Sec fault F2-> steady
third fault f3-> steady
4th fault f4 -> steady

This should be true if fault given in any order. First fault should flicker ,subsequent fault should be steady.kindly give some logic.

it's not clear to me what your code is attempting to do.
you code appears incomplete, lacking variable definitions

seems like a lot of repeated code that can probably be simplified using sub-functions

Please read these two posts:

General Guidance and How to use the Forum
and
Read this before posting a programming question ...

If you want to hire someone to write code for you then post in this forum:

Gigs and Collaborations

ToddL1962:
If you want to hire someone to write code for you then post in this forum:

Gigs and Collaborations

...and be prepared to explain the code and/or produce a functional description there, also.

i have 8 digital input. i will give digital input to it. i would like to know which digital input triggered first. i am using arduino mega board.

based on the input i would like to trigger led output. whenever first input is given it should blink for remaining input the led should be off.

Why does this section of code

   case 1:
      if (((Fault_Array[3] & 0x01) == 0x01) != intype.INF1) {
        Debounce1++;
        if (Debounce1 > 9) {
          if (((Fault_Array[3] & 0x01) == 0x01) != intype.INF1) {
            if ((FAULT_WINDOW[3] & 0x01) == 0x00) {
              FAULT_WINDOW[3] |= 0x01;

              PREVIOUS_FLT = LATEST_FLT;
              LATEST_FLT = 0x01;
              Debounce1 = 0;
            }

          }
        }

      } else
        Debounce1 = 0;
      break;

look so much like this section of code ?

    case 2:
      if (((Fault_Array[3] & 0x02) == 0x02) != intype.INF2) {
        Debounce2++;
        if (Debounce2 > 9) {
          if (((Fault_Array[3] & 0x02) == 0x02) != intype.INF2)

          {
            if ((FAULT_WINDOW[3] & 0x02) == 0x00) {
              FAULT_WINDOW[3] |= 0x02;

              PREVIOUS_FLT = LATEST_FLT;
              LATEST_FLT = 0x02;
              Debounce2 = 0;
            }
          }
        }
      } else
        Debounce2 = 0;
      break;

consider

// scan multiple buttons; flash LED corresponding to button pressed

byte butPins [] = { A1, A2, A3 };
byte ledPins [] = { 10, 11, 12 };

#define N_PINS sizeof(butPins)

byte butLst [N_PINS] = {};

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

    for (unsigned n = 0; n < N_PINS; n++)  {
        digitalWrite (ledPins [n], HIGH);
        pinMode      (ledPins [n], OUTPUT);

        pinMode      (butPins [n], INPUT_PULLUP);
        butLst [n]  = digitalRead (butPins [n]);
    }
}

// -----------------------------------------------------------------------------
int ledOn = -1;

void loop (void)
{
    static unsigned long msecLst = 0;
           unsigned long msec    = millis();

    for (unsigned n = 0; n < N_PINS; n++)  {
        byte but = digitalRead (butPins [n]);

        if (butLst [n] != but)  {
            butLst [n] = but;

            if (LOW == but) {     // button pressed
                if (-1 != ledOn)
                    digitalWrite (ledPins [ledOn], HIGH); // off
                ledOn = n;
            }
        }
    }

    if (-1 != ledOn)  {
        if (msec - msecLst > 100)  {
            msecLst = msec;
            digitalWrite (ledPins [ledOn], ! digitalRead (ledPins [ledOn]));
        }
    }

    delay (10);         // debounce
}
  Fault_Array[3] = 0X01;
  Fault_Array[3] = 0X02;
  Fault_Array[3] = 0X04;
  Fault_Array[3] = 0X08;

Why not simply

  Fault_Array[3] = 0X08;

?

(Whatever "Fault_Array" is...)

Dear all

I am looking for simple algorithm input.i cant post whole code. i pasted some part of it

i am using PISO to get input from 74hc165D ic. here i am trying to read data from DIP switch. Fault_Array[0] uses to read 8 position DIP switches

void PISO_INPUT(void) {
 unsigned char i;
 unsigned char j, k;
 unsigned char value;

 byteValue = 0; // accumulates image of 8 switches
 bitValue = 0;

 PISO_PL_EN = 0; // latch data


 PISO_PL_EN = 1; //ADD


 for (i = 0; i < Chk_Fault_Counter; i++) { //TBC // 8 bits

  bitValue = PISO_FAULT;
  byteValue |= (bitValue << ((Chk_Fault_Counter - 1) - i));

  PISO_CLK = 1;
  

  PISO_CLK = 0;
 

 }

 FAULT_PISO = byteValue;

 Fault_Array[0] = (unsigned char)(FAULT_PISO & 0xff);
 

}

Now i am trying to read above input and identifying which is latest input. IN this code assume i have 4 input F1,F2,F3,F4 where F4 is latest f3 is 3rd and f1 is first. as per below code F4 will be flashing and remaining F1,F2,F3,will be steady. i m expecting First input F1 flash first later should be steady
similarly if order F2 is first, F3,f1,F4 i/p F2 is first i/p it should be flashing and remaining should be steady.

here i am checking which input is latest input.

void CHK_WINDOW() {

 for (w = 0; w <= 8; w++) {
  switch (w) {

   case 1:
    if (((Fault_Array[0] & 0x01) == 0x01) != intype.INF25) {
     Debounce25++;
     if (Debounce25 >9) {
      if (((Fault_Array[0] & 0x01) == 0x01) != intype.INF25) {
       if ((WINDOW[0] & 0x01) == 0x00) {
        WINDOW[0] |= 0x01;
        PREVIOUS_FLT1 = PREVIOUS_FLT;
        PREVIOUS_FLT = LATEST_FLT;
        LATEST_FLT = 0x19;
        Debounce25 = 0;
       }
      }
     }

    } else
     Debounce25 = 0;
    break;

  

default:
    break;

  }

 }

}

i know problem is in these line of CHK_WINDOW() function.when input detected first time it move to latest one. later input comes it will move value to previous one.

here i expect once latest input address i might need to set one flag. if next input come ,if flag is already 1 then latest i/p remain same but previous & previous1 should be value.

WINDOW[0] |= 0x01;
PREVIOUS_FLT1 = PREVIOUS_FLT;
PREVIOUS_FLT = LATEST_FLT;
LATEST_FLT = 0x19;