Hi all! I'm working on a code that moves a linear actuator up and down based on the input given by a joystick app. This is my first code for an arduino, but I'm familiar with java so I'm not really sure what went wrong syntax wise and I'm not really sure how to understand the errors.
This is the code:
#include<Arduino.h>
#include<BluetoothSerial.h>
//Create BluetoothSerial object to communicate with app (Bluetooth module)
BluetoothSerial SerialBT;
const int relayPin=3; //Digital pin 3 connected to IN3 of the relay
const int powerPin=4; //Digital pin 4 (used as 5V power pin)
String command;
void setup() {
// put your setup code here, to run once:
pinMode(relayPin, OUTPUT); //set relayPin as output
pinMode(powerPin, OUTPUT); //set powerpin as output
Serial.begin(9600); //Baud rate for serial communication
SerialBT.begin("MyActuator");
}
void loop() {
// put your main code here, to run repeatedly:
if (SerialBT.available() > 0){
String command=SerialBT.readStringUntil('/n');
command.trim();
if (command=="R"||command=="U"){
digitalWrite(relayPin, HIGH);
delay(1000);
digitalWrite(relayPin, LOW);
}
else if(command=="D"||command=="L"){
digitalWrite(relayPin, LOW);
delay(2000);
digitalWrite(relayPin, HIGH);
}
else if(command=="S"){
digitalWrite(relayPin, LOW);
}
else{
Serial.println("Invalid comment");
}
}
}
This is the error:
Users/aayonavikram/Documents/Arduino/Linear_Actuator_Control/Linear_Actuator_Control.ino:7:17: error: no matching function for call to 'BluetoothSerial::BluetoothSerial()'
BluetoothSerial SerialBT;
^~~~~~~~
In file included from /Users/aayonavikram/Documents/Arduino/Linear_Actuator_Control/Linear_Actuator_Control.ino:4:0:
/Users/aayonavikram/Documents/Arduino/libraries/BluetoothSerial/src/BluetoothSerial.h:42:5: note: candidate: BluetoothSerial::BluetoothSerial(arduino::HardwareSerial&, bool)
BluetoothSerial(HardwareSerial& serial, bool verbose = true);
^~~~~~~~~~~~~~~
/Users/aayonavikram/Documents/Arduino/libraries/BluetoothSerial/src/BluetoothSerial.h:42:5: note: candidate expects 2 arguments, 0 provided
/Users/aayonavikram/Documents/Arduino/libraries/BluetoothSerial/src/BluetoothSerial.h:17:7: note: candidate: constexpr BluetoothSerial::BluetoothSerial(const BluetoothSerial&)
class BluetoothSerial {
^~~~~~~~~~~~~~~
/Users/aayonavikram/Documents/Arduino/libraries/BluetoothSerial/src/BluetoothSerial.h:17:7: note: candidate expects 1 argument, 0 provided
/Users/aayonavikram/Documents/Arduino/libraries/BluetoothSerial/src/BluetoothSerial.h:17:7: note: candidate: constexpr BluetoothSerial::BluetoothSerial(BluetoothSerial&&)
/Users/aayonavikram/Documents/Arduino/libraries/BluetoothSerial/src/BluetoothSerial.h:17:7: note: candidate expects 1 argument, 0 provided
/Users/aayonavikram/Documents/Arduino/Linear_Actuator_Control/Linear_Actuator_Control.ino: In function 'void setup()':
/Users/aayonavikram/Documents/Arduino/Linear_Actuator_Control/Linear_Actuator_Control.ino:21:30: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
SerialBT.begin("MyActuator");
^
In file included from /Users/aayonavikram/Documents/Arduino/Linear_Actuator_Control/Linear_Actuator_Control.ino:4:0:
/Users/aayonavikram/Documents/Arduino/libraries/BluetoothSerial/src/BluetoothSerial.h:51:10: note: initializing argument 1 of 'void BluetoothSerial::begin(int)'
void begin(int baudRate = 9600);
^~~~~
/Users/aayonavikram/Documents/Arduino/Linear_Actuator_Control/Linear_Actuator_Control.ino: In function 'void loop()':
/Users/aayonavikram/Documents/Arduino/Linear_Actuator_Control/Linear_Actuator_Control.ino:35:16: error: 'class BluetoothSerial' has no member named 'available'
if (SerialBT.available() > 0){
^~~~~~~~~
/Users/aayonavikram/Documents/Arduino/Linear_Actuator_Control/Linear_Actuator_Control.ino:36:49: error: no matching function for call to 'BluetoothSerial::readStringUntil(int)'
String command=SerialBT.readStringUntil('/n');
^
In file included from /Users/aayonavikram/Documents/Arduino/Linear_Actuator_Control/Linear_Actuator_Control.ino:4:0:
/Users/aayonavikram/Documents/Arduino/libraries/BluetoothSerial/src/BluetoothSerial.h:33:12: note: candidate: arduino::String BluetoothSerial::readStringUntil(char, int)
String readStringUntil(char terminator, int timeout);
^~~~~~~~~~~~~~~
/Users/aayonavikram/Documents/Arduino/libraries/BluetoothSerial/src/BluetoothSerial.h:33:12: note: candidate expects 2 arguments, 1 provided
/Users/aayonavikram/Documents/Arduino/Linear_Actuator_Control/Linear_Actuator_Control.ino:53:16: error: 'class BluetoothSerial' has no member named 'println'
SerialBT.println("Invalid comment");
^~~~~~~
exit status 1
Compilation error: no matching function for call to 'BluetoothSerial::BluetoothSerial()'
Thank you for the help!