Arduino Stair shield sketch, help needed

Hi,

I have set up a Arduino Stair shield with a Arduino Nano.
Have used the sketches supplied with the shield, but I'm in need for some assistant for it to work for my setup.

The sketch is very basic. The lights are triggered when corresponding I/O is triggered. Top and bottom of the stair.
The problem is that when the sensor is re-triggered the fadeout is not reset.

Say, that the light is set to be on for 1min. If one person triggers the arduino, and then a new person walk the stair after 55 seconds, the light would start to turn off before the second person is at the top/bottom.

Is there a way in Arduino to start a counter when triggered, and maybe reset this counter when re-triggered. If the counter is running.
If the counter is not running, then start one of the sequences.

Is this something the Arduino can do?

ASLFirstLast.ino (6.0 KB)

Can you please post a link to the Stair shield.

In future, please post your sketch in a post using code tags.

OP's code

#define SHIFTPWM_NOSPI                            //  Uncomment this part to NOT use the SPI port and change the pin numbers. This is 2.5x slower  Do not change!!!
const int ShiftPWM_dataPin = 6;                   //  Do not change!!!
const int ShiftPWM_clockPin = 7;                  //  Do not change!!!
const int ShiftPWM_latchPin = 8;                  //  Do not change!!!
#include <ShiftPWM.h>
const bool ShiftPWM_invertOutputs = false;         
const bool ShiftPWM_balanceLoad = false;         
#define sensorLight_PIN A5                        // Light sensor  Do not change!!!
#define sensorBottom_PIN A2                       // Bottom sensor Do not change!!!                     
#define sensorUpper_PIN A1                        // Upper sensor  Do not change!!!
unsigned char maxBrightness = 180;                // Here you set the number of brightness levels. Adjust(0-255)!!
int bRlaStFirst= 10;                              // Adjust brightness first and last steps!!!!!
unsigned char pwmFrequency = 75;                  // These values affect the load of ShiftPWM 
unsigned int numRegisters = 3;                    // Number of shift registers Do not change!!!
unsigned int numOutputs = numRegisters * 8;
unsigned int numRGBLeds = numRegisters * 8 / 3;
boolean sensorUpperActive,sensorBottomActive = false;
int numberOfstairs=19;                             // Setup Number of Your stairs. Adjust UP TO 24 !!!!
int pause=20000;                                   // Delay Time ON/OFF  Adjust!!! 
byte faidoutSpeed=5;                              // How fast to fadeout     Adjust!!!
byte faidinSpeed=15;                               // How fast to fadein      Adjust!!!
int val;
enum {NIGHT_MODE_ON,AUTO_READY,NIGHT_MODE_OFF};
uint8_t STATE;

void setup() {


  
  ShiftPWM.SetAmountOfRegisters(numRegisters);
  ShiftPWM.Start(pwmFrequency, maxBrightness);
  pinMode(sensorBottom_PIN, INPUT);
  pinMode(sensorUpper_PIN, INPUT);
  pinMode(sensorLight_PIN, INPUT_PULLUP);
  delay(500);
  }



void loop() {

val = analogRead(5);                                       //Checking light level
 
  switch (STATE) {

       case NIGHT_MODE_ON:

            ShiftPWM.SetOne(0,bRlaStFirst);
            ShiftPWM.SetOne(numberOfstairs-1,bRlaStFirst);
            STATE =  AUTO_READY;
        
        break;
        
       case AUTO_READY:
                                                   
            BottomTriggerFire();                           //Checking bottom sensor
            UpperTrigerFire();                             //Checking upper sensor
            switchONOFFfromdown();                         //Stairs on/off from down to up
            switchONOFFfromUp();                           //Stairs on/off from up to down
            if (val < 100 ) {                               //Photocell cencivity.  Adjust!!!!!!!!
              STATE = NIGHT_MODE_OFF;
           }
           
        break;

        case NIGHT_MODE_OFF:
    
            ShiftPWM.SetAll(0); 
             if (val > 100 ) {                              //Photocell cencivity. Adjust !!!!!!!!
              STATE = NIGHT_MODE_ON;
           } 
        break;  
 }
}

void BottomTriggerFire() {

  if (analogRead (sensorBottom_PIN) >= 300 && sensorUpperActive == false ) {            //Depends of the sensor type, if 0 when triggered ,than change the comparison to opposite value
    sensorBottomActive = true;
  }
}

void UpperTrigerFire() {

  if (analogRead(sensorUpper_PIN) >= 300 && sensorBottomActive == false ) {
    sensorUpperActive = true;
  }
}


void switchONOFFfromdown() {
  if (sensorBottomActive==true && sensorUpperActive==false){
    
        for (int a=bRlaStFirst; a<maxBrightness;a++){ 
          ShiftPWM.SetOne(0,a);
          delay(faidoutSpeed);
           }
        for(int i=1; i<numberOfstairs-1; i++){          
          for(int a=0; a<maxBrightness; a++){
          ShiftPWM.SetOne(i,a);
          delay(faidoutSpeed);
           }
          }
        for (int a=bRlaStFirst; a<maxBrightness;a++){ 
          ShiftPWM.SetOne(numberOfstairs-1,a);
          delay(faidoutSpeed);
           } 
           
        delay(pause); 


        for(int a=maxBrightness; a>=bRlaStFirst; a--){
        ShiftPWM.SetOne(0,a);
        delay(faidinSpeed);
           }
           
        for(int i=1; i<numberOfstairs-1; i++){
          for(int a=maxBrightness;a>=0;a--){
          ShiftPWM.SetOne(i,a);
          if(a==0){
          ShiftPWM.SetOne(i,0);  
          }
          delay(faidinSpeed);
           }
          }
          
        for(int a=maxBrightness; a>=bRlaStFirst; a--){
        ShiftPWM.SetOne(numberOfstairs-1,a);
        delay(faidinSpeed);
           }
        sensorBottomActive = false ;  
  }
}


 void switchONOFFfromUp () {
    if ( sensorUpperActive==true && sensorBottomActive==false) {

        for (int a=bRlaStFirst; a<maxBrightness;a++){ 
        ShiftPWM.SetOne(numberOfstairs-1,a);
        delay(faidoutSpeed);
           }
        for(int i=numberOfstairs-2; i>0; i--){
          for(int a=0; a<maxBrightness; a++){
          ShiftPWM.SetOne(i,a);
          delay(faidoutSpeed);
           }
          }
        for (int a=bRlaStFirst; a<maxBrightness;a++){ 
        ShiftPWM.SetOne(0,a);
        delay(faidoutSpeed);
         } 
          
     
        delay(pause); 

        for(int a=maxBrightness; a>=bRlaStFirst; a--){
        ShiftPWM.SetOne(numberOfstairs-1,a);
        delay(faidinSpeed);
           }   
        for(int i=numberOfstairs-2; i>0; i--){
          for(int a=maxBrightness;a>=0;a--){
          ShiftPWM.SetOne(i,a);
          if(a==0){
          ShiftPWM.SetOne(i,0);  
          }
          delay(faidinSpeed);
           }
          }
        for(int a=maxBrightness; a>=bRlaStFirst; a--){
        ShiftPWM.SetOne(0,a);
        delay(faidinSpeed);
           }   
        sensorUpperActive= false ;  
  }
}


    
    

        

  

Sorry about that, will remember it for next time! :slight_smile:

This is the shield: Automatic led stairs lighting controller arduino shield | eBay