Sunday, March 3, 2024

motor – Arduino not reacting generally when studying serial instructions


When I’m sending hex numbers through laptop to the arduino leonardo, it generally will not react, however the serial monitor says that it was despatched. My code;

    void setup()
{
  Serial.start(9600);
  pinMode(9, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop()
{
  delay(100); // Anticipate 100 millisecond(s)
  Serial.println(Serial.learn());
  if (Serial.learn() == 49) {
    Serial.println("left");
    analogWrite(9, 1023);
    digitalWrite(A0, HIGH);
    analogWrite(10, 1023);
    digitalWrite(11, LOW);
  }
  if (Serial.learn() == 50) {
    Serial.println("proper");
    analogWrite(9, 1023);
    digitalWrite(A0, HIGH);
    analogWrite(10, 1023);
    digitalWrite(11, LOW);
  }
  if (Serial.learn() == 51) {
    Serial.println("backwards");
    analogWrite(9, 1023);
    digitalWrite(A0, LOW);
    analogWrite(10, 1023);
    digitalWrite(11, LOW);
  }
  if (Serial.learn() == 52) {
    Serial.println("forwards");
    analogWrite(9, 1023);
    digitalWrite(A0, HIGH);
    analogWrite(10, 1023);
    digitalWrite(11, HIGH);
  }
  if (Serial.learn() == 48) {
    Serial.println("cease");
    analogWrite(9, 0);
    digitalWrite(A0, LOW);
    analogWrite(10, 0);
    digitalWrite(11, LOW);
  }
}

After I ship the numbers 1,2,3,4, and 0, it reads what the command does. Pins A0 and D11 are route management for the motor controller, and pins D9 and D10 are velocity.

it is kinda a mess.

for an in depth plan, contact me right here.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles