Programming to turn the LED at PIN13 ON & OFF by sending 'P' through Serial Monitor at baud rate of 9600, uploading has been done without error but LED is not responding, HELP PLEASE!
#define pin_13 13
int p13=LOW;
void setup(){
pinMode(pin_13, OUTPUT);
digitalWrite(pin_13, p13);
Serial.begin(9600);
}
void loop(){
if (Serial.available()){
char c = Serial.read();
if (c == 'P'){
if (p13 == HIGH){
p13 = LOW;
}
else {
p13 = HIGH;
}
}
}
}
You are not writing to the led pin in loop, so what do you expect?
You don't have to define something for pin 13, you can use LED_BUILTIN.
There is no need to hold the led state in a variable, if needed you can just read it.
Please use code tags when posting code and try Ctrl-T in the IDE (before posting).
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
if (c == 'P') {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
}
}
You need to do digitalWrite to pin_13:
if (p13 == HIGH){
p13 = LOW; << here
}
else {
p13 = HIGH; << and here
}