Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Servo Control**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-07 09:36:44
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Create an arduino project that read info from an */
- /* app on bluetooth and depending which of 3 options */
- /* i choosen, starts one of the servo motor */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SoftwareSerial.h>
- #include <Servo.h> //https://github.com/arduino-libraries/Servo
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void readBluetoothData();
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t klapka1_Servomotor_PWMSignal_PIN_D3 = 3;
- const uint8_t klapka2_Servomotor_PWMSignal_PIN_D5 = 5;
- const uint8_t klapka3_Servomotor_PWMSignal_PIN_D6 = 6;
- /***** DEFINITION OF Software Serial *****/
- const uint8_t Bluetooth_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
- const uint8_t Bluetooth_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
- SoftwareSerial Bluetooth_HC05_mySerial(Bluetooth_HC05_mySerial_PIN_SERIAL_RX_A1, Bluetooth_HC05_mySerial_PIN_SERIAL_TX_A0);
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- uint8_t klapka1_Servomotor_PWMSignal_PIN_D3_rawData = 0;
- uint8_t klapka2_Servomotor_PWMSignal_PIN_D5_rawData = 0;
- uint8_t klapka3_Servomotor_PWMSignal_PIN_D6_rawData = 0;
- /****** DEFINITION OF SERVO OBJECTS *****/
- Servo servo1; // Servo for klapka1
- Servo servo2; // Servo for klapka2
- Servo servo3; // Servo for klapka3
- void setup(void)
- {
- // Initialize servo motors
- servo1.attach(klapka1_Servomotor_PWMSignal_PIN_D3);
- servo2.attach(klapka2_Servomotor_PWMSignal_PIN_D5);
- servo3.attach(klapka3_Servomotor_PWMSignal_PIN_D6);
- // Set pin modes
- pinMode(klapka1_Servomotor_PWMSignal_PIN_D3, OUTPUT);
- pinMode(klapka2_Servomotor_PWMSignal_PIN_D5, OUTPUT);
- pinMode(klapka3_Servomotor_PWMSignal_PIN_D6, OUTPUT);
- // Initialize Bluetooth communication
- Bluetooth_HC05_mySerial.begin(9600);
- }
- void loop(void)
- {
- // Read data from Bluetooth
- readBluetoothData();
- // Update outputs based on received data
- updateOutputs();
- }
- void readBluetoothData()
- {
- if (Bluetooth_HC05_mySerial.available()) {
- char command = Bluetooth_HC05_mySerial.read();
- switch (command) {
- case '1':
- klapka1_Servomotor_PWMSignal_PIN_D3_rawData = 255; // Full speed for servo 1
- klapka2_Servomotor_PWMSignal_PIN_D5_rawData = 0; // Stop servo 2
- klapka3_Servomotor_PWMSignal_PIN_D6_rawData = 0; // Stop servo 3
- break;
- case '2':
- klapka1_Servomotor_PWMSignal_PIN_D3_rawData = 0; // Stop servo 1
- klapka2_Servomotor_PWMSignal_PIN_D5_rawData = 255; // Full speed for servo 2
- klapka3_Servomotor_PWMSignal_PIN_D6_rawData = 0; // Stop servo 3
- break;
- case '3':
- klapka1_Servomotor_PWMSignal_PIN_D3_rawData = 0; // Stop servo 1
- klapka2_Servomotor_PWMSignal_PIN_D5_rawData = 0; // Stop servo 2
- klapka3_Servomotor_PWMSignal_PIN_D6_rawData = 255; // Full speed for servo 3
- break;
- default:
- // Invalid command, stop all servos
- klapka1_Servomotor_PWMSignal_PIN_D3_rawData = 0;
- klapka2_Servomotor_PWMSignal_PIN_D5_rawData = 0;
- klapka3_Servomotor_PWMSignal_PIN_D6_rawData = 0;
- break;
- }
- }
- }
- void updateOutputs()
- {
- // Write PWM signals to servos
- analogWrite(klapka1_Servomotor_PWMSignal_PIN_D3, klapka1_Servomotor_PWMSignal_PIN_D3_rawData);
- analogWrite(klapka2_Servomotor_PWMSignal_PIN_D5, klapka2_Servomotor_PWMSignal_PIN_D5_rawData);
- analogWrite(klapka3_Servomotor_PWMSignal_PIN_D6, klapka3_Servomotor_PWMSignal_PIN_D6_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement