Troubleshooting: Part of a program failing after ~30s

I think the problem is using an 'int' (16 bits) for previousTime. The millis() function returns an 'unsigned long' (32 bits). Are 32.768 seconds the int will overflow and go negative.