SHARE
TWEET

Untitled

a guest Jul 19th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int pinLED = 13;
  2. int ledStatus = 0;
  3.  
  4. void setup() {
  5.   // put your setup code here, to run once:
  6.   Serial.begin(115200);
  7.   pinMode(pinLED, OUTPUT);
  8.  
  9.   Serial.println("usage : write (turn on | turn off)");
  10. }
  11.  
  12. String Serialread()
  13. {
  14.   String buf ="";
  15.   char c;
  16.  
  17.   while(Serial.available() > 0) {
  18.     c = Serial.read();
  19.     buf.concat(c);
  20.     delay(10);
  21.   }
  22.  
  23.   return buf;
  24. }
  25.  
  26. void loop() {
  27.   // put your main code here, to run repeatedly:
  28.   String str = "";
  29.   digitalWrite(pinLED, ledStatus);
  30.  
  31.   str = Serialread();
  32.   if(str == "") {
  33.    
  34.   }
  35.   else if(str == "turn off") {
  36.     Serial.println(str);
  37.     ledStatus = 0;
  38.   }
  39.   else if(str == "turn on") {
  40.     Serial.println(str);
  41.     ledStatus = 1;
  42.   }
  43.   else {
  44.     Serial.println("usage : write (turn on | turn off)");
  45.   }
  46.  
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top