/*
  Wokwi | questions
  Bluetooth serial monitor

  Alex — 11/15/24 at 9:26 PM
  I'm trying to figure out how I can use the "serial bluetooth terminal"
  app on my phone to assign a value to the variable "numRedBlink" but
  I'm afraid I have no clue what I'm doing...
*/

#include<SoftwareSerial.h>

//Variables
int redLED = 7;
int onTime = 400;
int offTime = 400;
int numRedBlink;

SoftwareSerial btSerial(2, 3); // RX, TX

void setup() {
  //Turn on serial ports
  Serial.begin(9600);
  btSerial.begin(9600);
  // Assign pin mode
  pinMode(redLED, OUTPUT);
}

void loop() {

  if (btSerial.available())
    Serial.write(btSerial.read());
  if (Serial.available())
    btSerial.write(Serial.read());

  //Set number of blinks for red
  Serial.println("How many red blinks? "); //Prompt
  while (Serial.available() == 0) {  } //Wait
  numRedBlink = Serial.parseInt(); //Read

  //Red blink for loop
  for (int j = 1; j <= numRedBlink; j = j + 1) { // Counter

    digitalWrite(redLED, HIGH); // Turn red LED on
    Serial.print("Red blink #"); // Print # of blinks
    Serial.println(j);
    delay (onTime);
    digitalWrite(redLED, LOW); // Turn red LED off
    delay (offTime);
  }
  Serial.println(" ");


}