Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int pwm = 2 ; //initializing pin 2 as pwm
- const int in_1 = 8 ;
- const int in_2 = 9 ;
- char myCol[20];
- void setup() {
- Serial.begin (115200);
- pinMode(pwm,OUTPUT) ; //we have to set PWM pin as output
- pinMode(in_1,OUTPUT) ; //Logic pins are also set as output
- pinMode(in_2,OUTPUT) ;
- }
- void loop() {
- int lf = 10;
- if (Serial.available() > 0) {
- Serial.readBytesUntil(lf, myCol, 1);
- if(strcmp(myCol,"o") == 0){
- digitalWrite(in_1,HIGH) ;
- digitalWrite(in_2,LOW) ;
- analogWrite(pwm,255) ;
- }
- else if(strcmp(myCol,"a") == 0){
- digitalWrite(in_1,LOW) ;
- digitalWrite(in_2,HIGH) ;
- }
- else if(strcmp(myCol,"b") == 0)
- {
- digitalWrite(in_1,LOW) ;
- digitalWrite(in_2,LOW) ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement