#define ledPin 13
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
Serial.println("You can type numbers 1,0 or the charchter B or M");
}
void loop()
{
int i = 0;
if (Serial.available() > 0)
{
char data = Serial.read();
if (data == '1')
{
//Turn on
digitalWrite(ledPin, HIGH);
Serial.println("you have pressed the number 1");
}
else if (data == '0')
{
// Turn off
digitalWrite(ledPin, LOW);
Serial.println("you have pressed the number 0");
}
else if (data == 'B')
{
// Blink
Serial.println("you have pressed the letter B");
while (i < 3)
{
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
i++;
}
}
else if (data == 'M')
{
// Send a message to the monitor
Serial.println("you have pressed the letter M");
Serial.println("I learned how to use serial communication between the computer and Arduino.");
}
}
}