Since I am newbie in Arduino and C/C++ programming language (I studied mostly Pascal and HTML/JavaScript in high school and only a couple of classes of C/C++ ), I humbly ask for your advice.
So, I'll leave here the code I wrote for this application that requires an input number "x" in Serial Monitor, by which the LED (the yellow Led in my case) will blink "x" times when button A is pressed. For example, if I type "4" in the Serial Monitor, the led will blink 4 times when I press the button.
Here's the code:
#define buttonA 14
#define LedYellow 13
int blinkingtimes = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LedYellow, OUTPUT);
pinMode(buttonA, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int statusButtonA = 0;
statusButtonA = digitalRead(buttonA);
if (statusButtonA = HIGH){
Serial.print("Introduce the on-off commutation number of the yellow LED ");
if(Serial.available() > 0){
blinkingtimes = Serial.read();
}
while (blinkingtimes > 0){
digitalWrite(LedYellow, HIGH);
delay(500);
blinkingtimes = blinkingtimes - 1;
}
}
}
Thank you in advance!
Have a great week ahead!