Quick help with millis()
hi,
i`m trying make sort of protection touch buttons when don`t need use them become inactive.
i`ve made simple statement in void loop(), when press button more 3 seconds void activetouch should loop self 10 second , quit if no input detected or if input detected 10 second countdown should go 0 every time touch pad active.
so
symptons @ moment - code goes straight activetouch, not waiting user input.
any suggestions??
thanks
i`m trying make sort of protection touch buttons when don`t need use them become inactive.
i`ve made simple statement in void loop(), when press button more 3 seconds void activetouch should loop self 10 second , quit if no input detected or if input detected 10 second countdown should go 0 every time touch pad active.
so
code: [select]
const byte button1 = 30;
const byte button2 = 32;
const byte led1 = 22;
const byte led2 = 23;
const byte redpin = 12;
const byte greenpin = 11;
const byte bluepin = 10;
byte buttonstate;
byte laststate = low;
byte count = 0;
int lastreading = high;
byte hold = false;
unsigned long switchon = 0;
const unsigned int holdtime = 3000;
const unsigned int deactivatetime = 10000;
void setup()
{
serial.begin(9600);
pinmode(button1, input_pullup);
pinmode(button2, input_pullup);
pinmode(led1, output);
pinmode(led2, output);
pinmode(redpin, high);
pinmode(greenpin, high);
pinmode(bluepin, high);
}
void loop()
{
if(digitalread(button1) == low)
{
switchon = millis();
serial.println(switchon);
}
if((millis() - switchon) > holdtime)
{
activetouch();
}
}
void activetouch()
{
bool deactivated = false;
unsigned long activetime = 0;
while(!deactivated)
{
digitalwrite(led1, !digitalread(button1));
digitalwrite(led2, !digitalread(button2));
activetime = millis();
serial.println("active");
}
if ((millis() - activetime) > deactivatetime)
{
deactivated = true;
}
}
symptons @ moment - code goes straight activetouch, not waiting user input.
any suggestions??
thanks
you want unsigned longs not ints times.
Arduino Forum > Using Arduino > Programming Questions > Quick help with millis()
arduino
Comments
Post a Comment