I control 2 LEDs with arduino uno , and that works as long as the serial monitor is opend, but when I close the seriel monitor, then the LEDs are off. So (there is no instructions).
But I want to save the user instructions entered in the serial monitor so that LEDs stay on as if it is still opend. The code is as a following .Could someone help me?
int data=0;
int CAN12=4;
int ledboard=13;
int reset=0;
void setup() {
Serial.begin(9600); //initialize serial COM at 9600 baudrate
pinMode(ledboard, OUTPUT); //make the LED pin (13) as output
digitalWrite (LED_BUILTIN, LOW);
pinMode(reset, OUTPUT);
pinMode(CAN12, OUTPUT);
pinMode(3, OUTPUT);
Serial.println("Hi!, I am Arduino");
}
void loop() {
while (Serial.available()> 0){
data = Serial.read();
Serial.println(data);
}
if (data=='A') {
digitalWrite (3, HIGH);
}
else if (data=='a') {
digitalWrite (3, LOW);
}
if (data=='B') {
digitalWrite (4, HIGH);
}
else if (data=='b') {
digitalWrite (4, LOW);
}
}
I know that opening the Serial Monitor causes the Arduino to reset, but I have never investigated whether that also happens when you close the Serial Monitor.
Of course, if you disconnect the Arduino from the PC it will forget everything except the program.
I just tried the program from the Original Post (unchanged, except for indenting) on my Uno and it works as expected. When I operate the program in the Serial Monitor I can turn the LEDs on and when I close the Serial Monitor they stay on.
And it behaves the same when I use the Minicom terminal program.
could anyone try this compleceted code? even this trivial code did not funktion. the led on the board turned off when i close the serial monitor. . this would help me a lot if i find the solution.