#include <Servo.h>
#define MOS 3

Servo myservo;  // create servo object to control a servo
int pos = 0;     // variable to store the servo position

int dataBuff;

void setup()
{
  Serial.begin(9600);
  Serial.print("BLUE");

  pinMode(13, OUTPUT);  // for bluetooth set up testing
  delay(500);

  myservo.attach(9);  // attaches the servo on pin 9 to the servo object

  pinMode(MOS,OUTPUT); 
}

void loop()
{
   analogWrite(MOS, 100);        // set power
      
}

void serialEvent()
{
  char dataBuff = 0;             // ?
  if (Serial.available() > 0)
  { // when receives messages

    dataBuff = Serial.read();    // store input to variable dataBuff

    if (dataBuff == '1')
    { // 1 = Green Tea
     analogWrite(MOS, 50);        // set power to 10  
     delay(3000);                 // brew for 1 minute
     analogWrite(MOS, 1);         // reset power to 1
     
      pos = 0;                   // servo lifting up tea bag
      do
      {
        myservo.write(pos);
        delay(15);
        pos = pos + 1;
      }  while (pos < 150);
    }

    if (dataBuff == '2')
    { // 2 = Black Tea
      analogWrite(MOS, 90);        // set power to 10  
      delay(5000);                 // brew for 1 minute
      analogWrite(MOS, 1);         // reset power to 1
     
      pos = 0;                   // servo lifting up tea bag
      do
      {
        myservo.write(pos);
        delay(15);
        pos = pos + 1;
      }  while (pos < 150);
    }

    if (dataBuff == '3')
    { // 3 = Oolong Tea
      analogWrite(MOS, 80);        // set power to 10  
      delay(9000);                 // brew for 1 minute
      analogWrite(MOS, 1);         // reset power to 1
     
      pos = 0;                   // servo lifting up tea bag
      do
      {
        myservo.write(pos);
        delay(15);
        pos = pos + 1;
      }  while (pos < 150);
    }

  }
}