r/ArduinoProjects • u/ParabolaXYZ • Jan 22 '17
How do I write an arduino code for this?
A spdt switch that control weather the flow of energy goes to a 5V arduino or an 12V sucking electromagnet. When the flow is stopped on the electromagnet I need it to start a timer on the arduino and when vibration is detected by Piezo Vibration Sensor the timer is to stop.
0
Upvotes
1
u/CatzRuleZWorld Jan 23 '17
This may not be what you're looking for but based on your specification, this is the best I can think of. Also, don't know if it'll work in practice but in theory it should I think...
bool timerActive; double timer;
void setup{ timer = 0.0; }
void loop{ if (electromagnetThing){ timerActive = true; } if (vibration){ timerActive = false; } if (timerActive){ timer += 0.001; } millis(1); }