calculate state in a function
Implement auto reset