Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3.  
  4. const int rx = 1;  //Andiamo ad assegnare al pin 2 l’indirizzo di ricezione dati (e lo colleghiamo al pin TXD del modulo)
  5. const int tx = 0;  //Assegnamo invece al pin 3 l’indirizzo di trasmissione dati (collegandolo al pin RXD del nostro componente
  6. char c=0;
  7. int LED=8;
  8. SoftwareSerial mySerial(rx, tx);
  9.  
  10. void setup(){
  11. pinMode(LED,OUTPUT);
  12. mySerial.begin(9600);
  13. }
  14.  
  15. void loop(){
  16. if (mySerial.available()>0){
  17.   c = mySerial.read();
  18.   if (c== '1'){                //LED blinks one time
  19.    digitalWrite(LED,HIGH);  //LED on for 300ms
  20.    delay(300);  
  21.    digitalWrite(LED,LOW);   //LED turns off
  22.    delay(500);
  23.   }
  24.   if(c=='2'){                 //LED blinks two times
  25.     digitalWrite(LED,HIGH); //LED on for 300ms
  26.    delay(300);
  27.    digitalWrite(LED,LOW);   //LED turns off
  28.    delay(500);
  29.    digitalWrite(LED,HIGH);  //LED on for 300ms
  30.    delay(300);
  31.    digitalWrite(LED,LOW);   //LED turns off
  32.    delay(500);
  33.   }
  34.    if(c=='3'){                //LED blinks three times
  35.     digitalWrite(LED,HIGH); //LED on for 300ms
  36.    delay(300);
  37.    digitalWrite(LED,LOW);   //LED turns off
  38.    delay(500);
  39.    digitalWrite(LED,HIGH);  //LED on for 300ms
  40.    delay(300);
  41.    digitalWrite(LED,LOW);   //LED turns off
  42.    delay(500);
  43.    digitalWrite(LED,HIGH); //LED on for 300ms
  44.    delay(300);
  45.    digitalWrite(LED,LOW);//LED turns off
  46.    delay(500);
  47.   }
  48. }delay(500);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement