Need help debouncing a button (Very bad at programming)

I am creating a automatic blind closer and opener. I have automated part and manual and I use a switch to toggle between them. The only part that I am struggling on is the switching between them cleanly. When I flick the switch, nothing happens and I do not know what is happening. Can someone take a look at my code and see what is wrong with it? Also do I need to debounce the switch? (P.S. I am not very good at programing, so anything will help) Thanks! Here is my code:

 int O = 7; //Open button
 int C = 11; //Close button
 int M = 12; //manual 
 int A = 8; //automatic switch
 int L = 13;
 int CP = 2;
 int AP = 3;
#include <SoftwareSerial.h>

void setup()
{
   pinMode(CP, OUTPUT);
   pinMode(AP, OUTPUT);
   pinMode(L, OUTPUT);
   pinMode(O, INPUT);
   pinMode(C, INPUT);
   pinMode(M, OUTPUT);
   pinMode(A, INPUT);
  Serial.begin(9600);
}

void loop()
{
  digitalWrite(AP, HIGH);
  
if (digitalRead(A) == LOW);
 {
  Serial.println("Manual");
 }
   if (digitalRead(A) == HIGH); 
  {
    Serial.println("Automatic");
  }
}

The very first thing you should do, is change the variable names you are using to human readable form. So "O" becomes "openButton" for example. Otherwise, nobody can wade through your code and understand it. And, soon you might find yourself in that position. :slight_smile:

Please supply us with a schematic whenever possible with your inquiries.
Do switches go to GND or VCC.
Do you have pull-ups on inputs, maybe you want to enable pull-ups.
Maybe you want to add a capacitor from an input to GND to help with bounce.
Loop runs very fast, at the top of which you digitalWrite(AP, HIGH);
But you never digitalWrite(AP, LOW); anywhere.

Try to stay in the habit of adding comments to your lines.

Maybe slow down a bit, go through the examples that come with the IDE to get some experience in Arduino programming.

Carlsnarel:
When I flick the switch, nothing happens

void loop()

{
 digitalWrite(AP, HIGH);
 
if (digitalRead(A) == LOW);
{
 Serial.println("Manual");
}
  if (digitalRead(A) == HIGH);
 {
   Serial.println("Automatic");
 }
}

What switch are you "flicking"
What do you expect should happen?
What does happen?

This piece of code seems to do nothing except print two alternative things on the Serial Monitor. Do you see either of them?

The loop() probably repeats much too fast to be useful. Temporarily add delay(1000); at the bottom of loop() - just before the final }

PLUS all of the advice in previous posts ...

...R