Trying to control robot vehicle Adafruit L293D motor with random functions

Hi, first post. I am fairly competent with JavaScript and have been trying to control my robot using the johnny-five library with a direct usb connection, so far to no avail.

I have already written a function which controls a mirobot drawing bot, I am trying to write the same code for Arduino, but have no exposure to C++.

This is my code:

#include <AFMotor.h>

AF_DCMotor motor1(3, MOTOR12_64KHZ);
AF_DCMotor motor2(4, MOTOR12_64KHZ);

int rndNumber;
int rndNumberLength;
int rndNumberArc;
word motor = 'motor1'; // does not work
word direction = 'FORWARD'; // does not work

void setup() 
{
  //Set initial speed of the motor & stop
  motor1.setSpeed(100);
  motor2.setSpeed(100);
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}

void drawLine ()
{
  uint8_t i;
  rndNumberLength = random(255); //  set random number between 1 and 255
  motor1.run(FORWARD); // both motors forward
  motor2.run(FORWARD);

  // Accelerate from zero to max speed defined by rndNumber
  for (i=0; i<rndNumberLength; i++) 
  {
    motor1.setSpeed(i);
    motor2.setSpeed(i);
    delay(10);
  }

  // Decelerate from maximum speed to zero
  for (i=255; i!=0; i--) 
  {
    motor1.setSpeed(i);
    motor2.setSpeed(i);
    delay(10);
  }

  // Now turn off motor
  motor1.run(RELEASE);
  motor2.run(RELEASE);
  delay(1000);

}

void drawArc ()
{
  uint8_t i;
  rndNumber = random(2); // set random numner between 1 and 2
  rndNumberArc - random(100); // set random number between 1 and 100
  if(rndNumber == 1) {
    motor = motor1;
    direction = FORWARD;
  } else {
    motor = motor2;
    direction = BACKWARD;
  }
  motor.run(direction);

  // Accelerate from zero to max speed defined by rndNumber
  for (i=0; i<rndNumberArc; i++) 
  {
    motor.setSpeed(i);
    delay(10);
  }

  // Decelerate from maximum speed to zero
  for (i=255; i!=0; i--) 
  {
    motor.setSpeed(i);
    delay(10);
  }

  // Now turn off motor
  motor.run(RELEASE);
  delay(1000);

}

void loop() 
{
  // rndNumber === 0 ? drawLine() : drawArc(); // convert this to C++
}

The basic premise is to initialise 1 of 2 functions depending on calling random number (between 1 and 2).

If 1 then run drawLine() function else drawArc(). That is the loop. Both the functions should also pass in random values for length, radius or time etc.

It seems to make sense to wrap these functions and then initialise them via a callback. I was trying to read up on that here:

  1. Gammon Forum : Electronics : Microprocessors : Function pointers / function callbacks / function variables
  2. why use callbacks - Programming Questions - Arduino Forum

If it helps anyone I have a jsfiddle here: Control micro-bit robot via JS - JSFiddle - Code Playground
Which contains pretty much the exact JS code. you can paste that code into this app: mirobot.io and see it working (sorry this is very roundabout).

I realise there are several errors in my code, I have been playing with this for some time, and decided to bite the bullet and hope someone here can help. TIA

word motor = 'motor1'; The datatype word is a sixteen bit numeric type.
The best multicharacter constant you could expect to hold in it would 'mo'.

I stopped reading at that point.

Thanks.

I've tried

String motor = String("motor1");
String motor = 'motor1';
char motor[5] = 'motor1';

All based on the Arduino reference.

All of them seem to throw errors.

I suppose if you compile to Assembler to upload code to a tiny computer on a satellite, then reserving memory per variable makes sense, but it's a pretty foreign concept to me.

I want to try and get my function working within 2 weeks if possible. My hope is that I will get some pointers and assistance here, I can even pay for assistance. But I would like to understand the code so that I can modify it later.

I think what I am going to struggle with is learning C++. If I can migrate my JS function that would be perfect, if that means having to try and wrestle with C++ variables I will try, but as I say it looks very foreign to me.

A String uses double quotes - I strongly suspect that is in the reference.

Best to not use Strings at all.