Hello,
New to this program and working on a watercraft project controlled by an arduino. Readings from sensors will be input from an external arduino to my Arduino Uno via a serial string of information. I am tasked with creating a program that will facilitate the simultaneous control of a servo motor for the rudder and an ESC to control the brushless motor for propulsion. I will attach what I code that I have been using below from Brushless motor control via Serial - Motors, Mechanics, Power and CNC - Arduino Forum [1]. My trouble is in adding in the code for the servo to react to serial communication. Thank you.
#include <Servo.h>
int MotorSpeed = 0;
Servo BrushlessMotor;
void arm(){
// Code modification necessary for use of ESC
setSpeed(30);
delay(1000); //delay 1 second, some speed controllers may need longer
}
void setSpeed(int speed){
// speed is from 0 to 100 where 0 is off and 100 is maximum speed
//the following maps speed values of 0-100 to angles from 0-180,
// some speed controllers may need different values, see the ESC instructions
int angle = map(speed, 0, 100, 0, 180);
BrushlessMotor.write(angle);
}
void setup()
{
BrushlessMotor.attach(12);
arm();
Serial.begin(9600);
pinMode(MotorSpeed, OUTPUT);
}
void loop()
{
MotorSpeed = Serial.read();
setSpeed(MotorSpeed);
delay(1000);
}
Code modified from user: "Acecombat" Brushless motor control via Serial - Motors, Mechanics, Power and CNC - Arduino Forum