SHARE
TWEET

Untitled

a guest Jan 23rd, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int pwm = 2 ; //initializing pin 2 as pwm
  2. const int in_1 = 8 ;
  3. const int in_2 = 9 ;
  4. char myCol[20];
  5. void setup() {  
  6.    Serial.begin (115200);  
  7.    pinMode(pwm,OUTPUT) ; //we have to set PWM pin as output
  8.    pinMode(in_1,OUTPUT) ; //Logic pins are also set as output
  9.    pinMode(in_2,OUTPUT) ;  
  10. }
  11. void loop() {
  12.   int lf = 10;
  13.   if (Serial.available() > 0) {
  14.   Serial.readBytesUntil(lf, myCol, 1);
  15.     if(strcmp(myCol,"o") == 0){
  16.         digitalWrite(in_1,HIGH) ;
  17.         digitalWrite(in_2,LOW) ;
  18.         analogWrite(pwm,255) ;      
  19.     }  
  20.     else if(strcmp(myCol,"a") == 0){
  21.         digitalWrite(in_1,LOW) ;
  22.         digitalWrite(in_2,HIGH) ;  
  23.     }  
  24.     else if(strcmp(myCol,"b") == 0)
  25.     {
  26.       digitalWrite(in_1,LOW) ;
  27.       digitalWrite(in_2,LOW) ;
  28.     }
  29.   }
  30. }
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