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.
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.