It's doing what you're asking then.
Your sketch is telling it to write your outPin to LOW if it see's the spike, and HIGH if the input is 0V (actually you're testing for values less than 0 too, but that's not going to happen with an analogRead value).
This next block after that is a legacy of when your system was reading a digital pin, and no longer does what the comments say it does
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis(); }
}
...since reading will never be HIGH, and you don't set previous at any stage now.
If you want to only toggle on high, and only after your 5sec debounce, something like this should do the trick:
int inPin = 0; // input pin is A0
int outPin = 7; // the number of the output pin (D7)
long time = 0; // the last time the output pin was toggled
long debounce = 5000; // the debounce time, increase if the output flickers
int reading; // the current reading from the input pin
int previous = LOW; // the most recent value written to outPin, also the initial state of that LED
void setup() {
pinMode(outPin, OUTPUT);
digitalWrite(outPin, previous); // set initial state
}
void loop() {
reading = analogRead(inPin); // read the value on analog input
if ( reading >= ((1 * 1023) / 5) ) { // greater than 1V
if (millis() - time > debounce) { // enough time has transpired to pay attention again
// toggle the output pin
if(previous == LOW)
previous = HIGH;
else
previous = LOW;
digitalWrite (outPin, previous);
time = millis(); // reset the timer
}
}
}
I didn't see your rationale for having both a state and a previous variable, so did away with one. And you'll notice there's no else component to either of the if statements at this time. The two nested IFs could be combined into a single one with an and (&&) in the logic but this gives you flexibility to do something else if the timer isn't up yet, by adding an else to that if you choose.
I'm hoping this buys me a reprieve from that previous silly post

Geoff