CARVIEW |
Select Language
HTTP/2 200
date: Sun, 12 Oct 2025 02:40:09 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=4ebfd6f950356e3deb168ff51ec80bd427b72aa4a00c25fcb991f3442a36f38ca%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22gBbR398R_fBNihwxKvlBVaaaPHZoxXiK%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d33b18ee7025e0-BLR
Bluetooth RC rev_01 - Pastebin.com
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: Bluetooth RC
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-08-27 12:18:24
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* rc car which uses bluetooth to control and need 2 */
- /* L298N motor driver ,4x4 */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <BluetoothSerial.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /****** PIN CONFIGURATION *******/
- // Left side (Motor 1 and Motor 2 on L298N #1)
- const int ENA_LEFT = 5; // PWM for Motor 1 (LEFT FRONT)
- const int IN1_LEFT = 18; // Motor 1 input A
- const int IN2_LEFT = 19; // Motor 1 input B
- const int IN3_LEFT = 21; // Motor 2 input A
- const int IN4_LEFT = 22; // Motor 2 input B
- const int ENB_LEFT = 23; // PWM for Motor 2 (LEFT REAR)
- // Right side (Motor 3 and Motor 4 on L298N #2)
- const int ENA_RIGHT = 25; // PWM for Motor 3 (RIGHT FRONT)
- const int IN1_RIGHT = 26; // Motor 3 input A
- const int IN2_RIGHT = 27; // Motor 3 input B
- const int IN3_RIGHT = 32; // Motor 4 input A
- const int IN4_RIGHT = 33; // Motor 4 input B
- const int ENB_RIGHT = 14; // PWM for Motor 4 (RIGHT REAR)
- /****** PWM CONFIGURATION *******/
- const int PWM_FREQ = 5000; // 5 kHz PWM frequency
- const int PWM_RES = 8; // 8-bit resolution (0-255)
- const int PWM_CH_LEFT_A = 0; // PWM channel for LEFT M1
- const int PWM_CH_LEFT_B = 1; // PWM channel for LEFT M2
- const int PWM_CH_RIGHT_A = 2; // PWM channel for RIGHT M3
- const int PWM_CH_RIGHT_B = 3; // PWM channel for RIGHT M4
- BluetoothSerial SerialBT;
- int currentSpeed = 150; // default speed (0-255)
- /****** PROTOTYPES FOR MOTOR CONTROL *******/
- void stopAllMotors();
- void driveLeftMotor(int motorIndex, int speed, int dir); // motorIndex: 0 -> M1, 1 -> M2
- void driveRightMotor(int motorIndex, int speed, int dir); // motorIndex: 0 -> M3, 1 -> M4
- void setLeftMotors(int dir, int speed);
- void setRightMotors(int dir, int speed);
- void driveAll(int dir, int speed);
- /****** IMPLEMENTATION ******/
- void setup(void)
- {
- // Initialize Bluetooth SPP
- SerialBT.begin("ESP32_RCCar");
- // Initialize pins
- pinMode(IN1_LEFT, OUTPUT);
- pinMode(IN2_LEFT, OUTPUT);
- pinMode(IN3_LEFT, OUTPUT);
- pinMode(IN4_LEFT, OUTPUT);
- pinMode(ENA_LEFT, OUTPUT);
- pinMode(ENB_LEFT, OUTPUT);
- pinMode(IN1_RIGHT, OUTPUT);
- pinMode(IN2_RIGHT, OUTPUT);
- pinMode(IN3_RIGHT, OUTPUT);
- pinMode(IN4_RIGHT, OUTPUT);
- pinMode(ENA_RIGHT, OUTPUT);
- pinMode(ENB_RIGHT, OUTPUT);
- // Setup PWM channels for ESC-like motor controllers
- ledcSetup(PWM_CH_LEFT_A, PWM_FREQ, PWM_RES);
- ledcAttachPin(ENA_LEFT, PWM_CH_LEFT_A);
- ledcSetup(PWM_CH_LEFT_B, PWM_FREQ, PWM_RES);
- ledcAttachPin(ENB_LEFT, PWM_CH_LEFT_B);
- ledcSetup(PWM_CH_RIGHT_A, PWM_FREQ, PWM_RES);
- ledcAttachPin(ENA_RIGHT, PWM_CH_RIGHT_A);
- ledcSetup(PWM_CH_RIGHT_B, PWM_FREQ, PWM_RES);
- ledcAttachPin(ENB_RIGHT, PWM_CH_RIGHT_B);
- // Stop all motors at startup
- stopAllMotors();
- }
- void loop(void)
- {
- if (SerialBT.available())
- {
- String cmd = SerialBT.readStringUntil('\n');
- cmd.trim();
- if (cmd.length() == 0) return;
- char c = cmd.charAt(0);
- if (c == 'S' || c == 's') // set speed: S<0-255>
- {
- String num = cmd.substring(1);
- int sp = num.toInt();
- if (sp < 0) sp = 0;
- if (sp > 255) sp = 255;
- currentSpeed = sp;
- }
- else if (c == 'F' || c == 'f') // move forward
- {
- driveAll(1, currentSpeed);
- }
- else if (c == 'B' || c == 'b') // move backward
- {
- driveAll(-1, currentSpeed);
- }
- else if (c == 'L' || c == 'l') // rotate left
- {
- setLeftMotors(-1, currentSpeed);
- setRightMotors(1, currentSpeed);
- }
- else if (c == 'R' || c == 'r') // rotate right
- {
- setLeftMotors(1, currentSpeed);
- setRightMotors(-1, currentSpeed);
- }
- else if (c == 'X' || c == 'x') // stop
- {
- stopAllMotors();
- }
- }
- delay(5);
- }
- void stopAllMotors()
- {
- setLeftMotors(0, 0);
- setRightMotors(0, 0);
- }
- void driveLeftMotor(int motorIndex, int speed, int dir)
- {
- int channel = (motorIndex == 0) ? PWM_CH_LEFT_A : PWM_CH_LEFT_B;
- int in1 = (motorIndex == 0) ? IN1_LEFT : IN3_LEFT;
- int in2 = (motorIndex == 0) ? IN2_LEFT : IN4_LEFT;
- if (dir > 0) {
- digitalWrite(in1, HIGH); digitalWrite(in2, LOW);
- } else if (dir < 0) {
- digitalWrite(in1, LOW); digitalWrite(in2, HIGH);
- } else {
- digitalWrite(in1, LOW); digitalWrite(in2, LOW);
- }
- ledcWrite(channel, (speed < 0) ? 0 : speed);
- }
- void driveRightMotor(int motorIndex, int speed, int dir)
- {
- int channel = (motorIndex == 0) ? PWM_CH_RIGHT_A : PWM_CH_RIGHT_B;
- int in1 = (motorIndex == 0) ? IN1_RIGHT : IN3_RIGHT;
- int in2 = (motorIndex == 0) ? IN2_RIGHT : IN4_RIGHT;
- if (dir > 0) {
- digitalWrite(in1, HIGH); digitalWrite(in2, LOW);
- } else if (dir < 0) {
- digitalWrite(in1, LOW); digitalWrite(in2, HIGH);
- } else {
- digitalWrite(in1, LOW); digitalWrite(in2, LOW);
- }
- ledcWrite(channel, (speed < 0) ? 0 : speed);
- }
- void setLeftMotors(int dir, int speed)
- {
- driveLeftMotor(0, speed, dir);
- driveLeftMotor(1, speed, dir);
- }
- void setRightMotors(int dir, int speed)
- {
- driveRightMotor(0, speed, dir);
- driveRightMotor(1, speed, dir);
- }
- void driveAll(int dir, int speed)
- {
- setLeftMotors(dir, speed);
- setRightMotors(dir, speed);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ X
JavaScript | 6 sec ago | 0.25 KB
-
📌 Instant BTC Profit Method ✅ Working
JavaScript | 8 sec ago | 0.24 KB
-
⭐✅ Swapzone Glitch ✅ Working ⭐⭐ X
JavaScript | 14 sec ago | 0.25 KB
-
📝 MAKE $2500 IN 15 MIN ✅ Working
JavaScript | 17 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ 7
JavaScript | 21 sec ago | 0.25 KB
-
💵 Make 3000$ in 20 minutes 💵
JavaScript | 26 sec ago | 0.24 KB
-
⭐✅ Swapzone Glitch ✅ Working ⭐⭐ P
JavaScript | 30 sec ago | 0.25 KB
-
📝 Crypto Swap Glitch ✅ Working
JavaScript | 35 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand