I have started learning simple electronics with Arduino and I have a simple project and that is my code I wanna to what is wring in it and how can I improve it ?
#include <Servo.h>
Servo myServo;
const int DCMotor = 10;
const int onOff = 11;
int switchState = 0;
int servoAngle = 0;
void setup() {
myServo.attach(9);
pinMode (DCMotor,OUTPUT);
pinMode (onOff,INPUT);
myServo.write (0);
digitalWrite (DCMotor,LOW);
}
void loop() {
switchState = digitalRead (onOff);
if (switchState = HIGH ){ // If the fan is on
digitalWrite (DCMotor,HIGH);
for (servoAngle = 0, servoAngle < 180, servoAngle++){
myServo.write (servoAngle);
delay (250);
}
if (servoAngle = 180){
for (servoAngle = 180, servo > 0, servoAngle -1){
myServo.write (servoAngle);
delay (250);
}
}
}
if (switchState = LOW){ // If the fan is Off
digitalWrite (DCMotor,LOW);
}
}