Advertisement
pleasedontcode

Humanoid rev_01

Nov 9th, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Humanoid
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2023-11-09 15:05:22
  15.     - Source Code generated by: Menaka
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <Servo.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. /* Moving Humanoid robot using bluetooth controlled */
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25. /* Moving Humanoid robot using bluetooth controlled */
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF PWM OUTPUT PINS *****/
  32. const uint8_t V1robo_Servomotor_PWMSignal_PIN_D2 = 2;
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. Servo myservo;
  36.  
  37. void setup(void)
  38. {
  39.   // put your setup code here, to run once:
  40.   myservo.attach(V1robo_Servomotor_PWMSignal_PIN_D2);
  41.  
  42.   // Set the serial communication baud rate
  43.   Serial.begin(9600);
  44. }
  45.  
  46. void loop(void)
  47. {
  48.   // put your main code here, to run repeatedly:
  49.  
  50.   // Check if there is any data available in the serial buffer
  51.   if (Serial.available() > 0) {
  52.     // Read the incoming data
  53.     char command = Serial.read();
  54.  
  55.     // Move the robot based on the received command
  56.     switch (command) {
  57.       case 'F': // Move forward
  58.         // Set the servo angle to move the robot forward
  59.         myservo.write(90);
  60.         break;
  61.       case 'B': // Move backward
  62.         // Set the servo angle to move the robot backward
  63.         myservo.write(180);
  64.         break;
  65.       case 'L': // Turn left
  66.         // Set the servo angle to turn the robot left
  67.         myservo.write(0);
  68.         break;
  69.       case 'R': // Turn right
  70.         // Set the servo angle to turn the robot right
  71.         myservo.write(180);
  72.         break;
  73.       case 'S': // Stop
  74.         // Set the servo angle to stop the robot
  75.         myservo.write(90);
  76.         break;
  77.       default:
  78.         break;
  79.     }
  80.   }
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement