Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement