Codi 4

In this project we are working with the micro conntroller MKR-1000



Here we will see an example video when the code is executed :



Here you have the code of the video example, he code is underlined :

    
   const int ledPIN = 8; // assigns the LED to pin 8
char data;
int option;

void setup() {
  Serial.begin(9600); // the Serial.begin(9600)
  pinMode(ledPIN , OUTPUT); // assigned as the output pin
}

 void loop(){
  if(Serial.available())
  data = Serial.read();
  if(data == '0') // off (0)
  {
    option = 0;
  }else if(data == '1') // on (1 )
  {
    option = 1;
  }else if(data == '2') // flashing (2)
  {
    option = 2;
  }
  switch (option)
  {
    case 0: // LED OFF
      digitalWrite(ledPIN, LOW);
    break;
    case 1: //LED ON
      digitalWrite(ledPIN, HIGH);
    break;
    case 2: // LED BLINK
      digitalWrite(ledPIN , HIGH);
      delay(200);
      digitalWrite(ledPIN, LOW);
      delay(200);
    break;
    do
    {
   digitalWrite(ledPIN , 1);
   delay(200);
   digitalWrite(ledPIN, 0);
   delay(200);
   digitalWrite(ledPIN , 1);
   delay(200);
   digitalWrite(ledPIN, 0);
   delay(200);
   digitalWrite(ledPIN , 1);
   delay(200);
   digitalWrite(ledPIN, 0);
   delay(200);
   digitalWrite(ledPIN , 1);
   delay(600);
   digitalWrite(ledPIN, 0);
   delay(200);
   digitalWrite(ledPIN , 1);
   delay(600);
   digitalWrite(ledPIN, 0);
   delay(200);
   digitalWrite(ledPIN , 1);
   delay(600);
   digitalWrite(ledPIN, 0);
   delay(200);
   digitalWrite(ledPIN , 1);
   delay(200);
   digitalWrite(ledPIN, 0);
   delay(200);
   digitalWrite(ledPIN , 1);
   delay(200);
   digitalWrite(ledPIN, 0);
   delay(200);
   digitalWrite(ledPIN , 1);
   delay(200);
   digitalWrite(ledPIN, 0);
  delay(200);
  }while(data == '2');
     break;
  }
}