Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This code is tested only for the provided RobotCo App You may need to change the alphabet for the control of the direction of robot.
- //Connection: Digital pin 4,5,6,7 to IN1,IN2,IN3,IN4 respectively.
- char state;
- void stp();
- void forward();
- void left();
- void right();
- void backward();
- void setup()
- {
- pinMode(4,OUTPUT);
- pinMode(5,OUTPUT);
- pinMode(6,OUTPUT);
- pinMode(7,OUTPUT);
- Serial.begin(9600);
- }
- void loop() {
- if(Serial.available() > 0) // Ckeck for command Recieved
- {
- state = Serial.read();
- Serial.println(state);
- flag=0;
- }
- if (state == 's') // Checking Command from User
- {
- stp();
- }
- else if (state == 'f')
- {
- right();
- }
- else if (state == 'b')
- {
- left();
- }
- else if (state == 'l')
- {
- backward();
- }
- else if (state == 'r')
- {
- forward();
- }
- } //loop() ends here
- void forward()
- {
- digitalWrite(4,HIGH);
- digitalWrite(5,LOW);
- digitalWrite(6,HIGH);
- digitalWrite(7,LOW);
- }
- void backward()
- {
- digitalWrite(4,LOW);
- digitalWrite(5,HIGH);
- digitalWrite(6,LOW);
- digitalWrite(7,HIGH);
- }
- void left()
- {
- digitalWrite(4,LOW);
- digitalWrite(5,HIGH);
- digitalWrite(6,HIGH);
- digitalWrite(7,LOW);
- }
- void right()
- {
- digitalWrite(4,HIGH);
- digitalWrite(5,LOW);
- digitalWrite(6,LOW);
- digitalWrite(7,HIGH);
- }
- void stp()
- {
- digitalWrite(4,LOW);
- digitalWrite(5,LOW);
- digitalWrite(6,LOW);
- digitalWrite(7,LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement