Hi friends. I want to turn off the smsfet defined pin after 10 seconds in the blow sketch but not success. can anyone help me to fix ? thanks
#include <avr/sleep.h>
#include <avr/interrupt.h>
#define TURN_ON_FET 0
#define MONITOR_SENSOR 1
#define FLASH 2
#define FETS 3
const byte voltageSensor = 0;
const byte flasherSwitch = 1;
const byte smsfet = 2;
const byte reedSwitch = 3;
const byte MOSFET = 4;
void setup()
{
pinMode( reedSwitch, INPUT );
pinMode( voltageSensor, INPUT );
pinMode( MOSFET, OUTPUT );
pinMode( flasherSwitch, OUTPUT );
pinMode( smsfet, OUTPUT );
sleep();
}
void loop()
{
unsigned long timeNow;
static unsigned long timeFunc;
static byte state = TURN_ON_FET;
timeNow = millis();
switch ( state )
{
case TURN_ON_FET:
digitalWrite( smsfet, HIGH );
digitalWrite( MOSFET, HIGH );
delay(5000);
timeFunc = timeNow;
state = MONITOR_SENSOR;
break;
case MONITOR_SENSOR:
if ( digitalRead(voltageSensor) == HIGH )
{
digitalWrite( MOSFET, LOW );
state = TURN_ON_FET;
digitalWrite( smsfet, LOW );
sleep();
}
else if ( (timeNow - timeFunc) >= 3000ul )
{
digitalWrite( flasherSwitch, HIGH );
timeFunc = timeNow;
state = FLASH;
}
break;
case FLASH:
if ( timeNow - timeFunc >= 50ul )
{
digitalWrite( flasherSwitch, LOW );
timeFunc = timeNow;
state = MONITOR_SENSOR;
}
break;
case FETS:
if ( (timeNow - timeFunc) >= 10000ul )
{
digitalWrite( smsfet, LOW );
}
}
}
void sleep() {
GIMSK |= _BV(PCIE);
PCMSK |= _BV(PCINT3);
ADCSRA &= ~_BV(ADEN);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei();
sleep_cpu();
cli();
PCMSK &= ~_BV(PCINT3);
sleep_disable();
ADCSRA |= _BV(ADEN);
sei();
}
ISR(PCINT0_vect) {
}