/********* 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 Motor
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-06-08 10:03:21
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* motors go forward and backward */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include //https://github.com/Aidywady/NXTBluetooth
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF Software Serial *****/
const uint8_t bt_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
const uint8_t bt_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
SoftwareSerial bt_HC05_mySerial(bt_HC05_mySerial_PIN_SERIAL_RX_A1, bt_HC05_mySerial_PIN_SERIAL_TX_A0);
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
NXTBluetooth bluetooth(bt_HC05_mySerial_PIN_SERIAL_RX_A1, bt_HC05_mySerial_PIN_SERIAL_TX_A0, 1, 1);
/****** MOTOR CONTROL PINS *****/
const uint8_t motorPin1 = 9; // Motor pin 1
const uint8_t motorPin2 = 10; // Motor pin 2
void setup(void)
{
// put your setup code here, to run once:
bt_HC05_mySerial.begin(9600); // Initialize SoftwareSerial for Bluetooth
bluetooth.begin(9600); // Initialize NXTBluetooth
Serial.begin(9600); // Initialize Serial for debugging
Serial.println("Beginning communication with NXT");
// Initialize motor control pins
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
}
void loop(void)
{
// put your main code here, to run repeatedly:
// Example motor control logic
// Move forward
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
delay(2000); // Move forward for 2 seconds
// Move backward
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
delay(2000); // Move backward for 2 seconds
// Stop motors
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
delay(1000); // Stop for 1 second
// Communication with NXT
String runTime = String((float) millis() / 1000, 3);
bluetooth.write(runTime, 0);
if (bluetooth.available(0)) {
Serial.println(bluetooth.read(0, true));
}
bluetooth.update();
}
/* END CODE */