 I have a code that makes it so that when I push a button, it says a phrase on the Serial Monitor. But when I push the button, the Serial monitor puts out both of my phrases I have set. I really need this code figured out by ten o' clock PM (pacific Standard Time)!

const int analogPin = A0;
int counter = 0;

void setup() {
Serial.begin(9600);
Serial.println("Mom, push the button once, wait about a second, then push it again.");
Serial.println("");

}

void loop() {

if (analogValue == 1023) {
counter = counter + 1;
} else {
counter = counter;
}

if (counter == 1 && analogValue == 1023) {
Serial.println("Happy Mothers Day!");
delay(500);
counter = counter + 1;
} else {
counter = counter;
}

if (counter == 2 && analogValue == 1023) {

Serial.println("I love you!");
delay(500);
counter = counter + 1;
} else {
counter = counter;
}

if (counter > 2) {
counter = 0;
}
}

How is it wired up?

here's some suggestions.

if (analogValue == 1023) { counter = counter + 1; } else { counter = counter; Un-needed - counter already equals counter }

if (counter == 1 && analogValue == 1023) { Serial.println("Happy Mothers Day!"); delay(500); counter = counter + 1; why are you now incrementing counter, because it now equals 2 } else { counter = counter; same here } And because it now equals 2 the following statement is true if (counter == 2 && analogValue == 1023) {

Serial.println("I love you!"); delay(500); counter = counter + 1; and counter now equals 3 } else { counter = counter; and here }

if (counter > 2) { counter = 0; } }

What can I do to fix it? My dad tells me that I need more than one void function. I think I have some idea of how that works, but I don't know if it will behave as a second loop.

I've been thinking about this all day. How do I make it so that I can increase the counter without making the second phrase true? should I use the for() statement?

I would change it so its a digital read, add some switch debouncing so it doesn't think u pressed it twice id post some code example but im on my phone so youl have to look thru the playground and the forum for some example

Ok. I think I get it now. I use digitalRead(), and use int val = digitalRead(digitalPin); int counter = counter + val;

that way I think it will make it so that second phrase isn't going to be automatically true.

What do you have in there to make the analog pin go high? I don't see any pullup or pulldown resistors that would make the pin sit high or low.

I would simplify things a little

inputPin = 14; // A0 pin
byte counter;
void setup(){
pinMode (inputPin, INPUT);
digitalWrite (inputPin, HIGH); // enable internal pullup
Serial.begin(9600);
Serial.println("Mom, push the button once, wait about a second, then push it again.");
Serial.println("");
}
void loop(){
if (digitalRead (inputPin) == LOW){ // pin is pulled high, close switch to connect to ground
counter = counter +1;
if (counter == 1){
Serial.println ("message 1");
delay (500); // debounce switch
} // end counter 1
if (counter == 2){
Serial.println ("message 2");
delay (500);
counter = 0;
} // end counter 2