Eng-Mohamed-Essam

Untitled

Oct 12th, 2019
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define LedPin 11
  2.  
  3. String Read, myString;
  4. int PWM;
  5.  
  6. void setup() {
  7.   pinMode(LedPin, OUTPUT);
  8.   Serial.begin(9600);
  9. }
  10.  
  11. void loop() {
  12.   if (Serial.available()){ // If there's available Serial Data
  13.     Read = Serial.readString(); // Read it as string
  14.     Read.substring(0, "\n"); // Reading from the first index to the end of the Command line
  15.     if(Read.indexOf(0) == "F" || Read.indexOf(0) == "f"){
  16.     PWM = Read.substring(1, "\n").toInt(); //Reading the PWM and Turning it into ints
  17.     digitalWrite(LedPin, PWM);
  18.     }
  19.     else if (Read.indexOf(0) == "B" || Read.indexOf(0) == "b"){
  20.       digitalWrite(LedPin, LOW);
  21.     }
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment