Arduino uno 4 button call sequence

Hi all. I have 2 pololu maestro 6 channel servo usb. I have added on button to arduino uno and call up sequence of 3 to 6 servo’s running and it works well. Here is my code for arduino:

include <PololuMaestro.h>
#ifdef SERIAL_PORT_HARDWARE_OPEN
  #define maestroSerial SERIAL_PORT_HARDWARE_OPEN
#else
  #include <SoftwareSerial.h>
  SoftwareSerial maestroSerial(10,11);
#endif
MicroMaestro maestro(maestroSerial);
const int buttonPin1 = A0;
const int buttonPin2 = A1;
int buttonState1 = 0;
int buttonState2 = 0;
void setup()
{
  maestroSerial.begin(9600);
  Serial.begin(9600);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
}
void loop()
{
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  if (buttonState1 == HIGH) {   
      maestro.restartScript(0);
      delay(4000);
  }
  else {
   maestro.stopScript();
  }

  if (buttonState2 == HIGH) {   
      maestro.restartScript(0);
      delay(4000);
  }
  else {
   maestro.stopScript();
  }
}

If you can see my code i added another button to call sequence but i don’t know how to call up a sequence via arduino to pololu. I want ad up to four buttons to call up different sequences. At this stage can only call up one. Could anyone help me on this please. Thank you in advance.

Hi anyone at Pololu

You have not posted your Maestro script, but from your Arduino sketch, it looks like you are not triggering any specific subroutines. In oder to get your button presses to have any meaning, you will have to incorporate subroutines into your Maestro script that correspond to the set of servo movements you want. Then, you can then restart your script at those subroutines using a different argument to restartScript(). The Maestro Library for Arduino’s Script.ino example shows how to do that. If you get stuck, post what code you have tried, what you expect it to do, and what it is actually doing, and I’ll see if I can help.

-Jon

Thank you for replying love your product. I don not under stand what you mean by your reply. Can you please tell me more or change my code that i send you. I also did connect 4 channel relay board in use 4 output to make 2 motors run forward and reverse. Wow love this tiny board. I gonna buy another on 12 channel maestro servo board.

My code for the arduino call up sequence

#include <PololuMaestro.h>
#ifdef SERIAL_PORT_HARDWARE_OPEN
  #define maestroSerial SERIAL_PORT_HARDWARE_OPEN
#else
  #include <SoftwareSerial.h>
  SoftwareSerial maestroSerial(10,11);
#endif
MicroMaestro maestro(maestroSerial);
const int buttonPin1 = A0;
const int buttonPin2 = A1;
int buttonState1 = 0;
int buttonState2 = 0;
void setup()
{
  maestroSerial.begin(9600);
  Serial.begin(9600);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
}
void loop()
{
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  if (buttonState1 == HIGH) {   
      maestro.restartScript(0); /////!!! Do i change it here like in (0) to a sequence number
      delay(4000);
  }
  else {
   maestro.stopScript();
  }

  if (buttonState2 == HIGH) {   
      maestro.restartScript(0); /////!!! Do i change it here like in (0) to a sequence number
      delay(4000);
  }
  else {
   maestro.stopScript();
  }

Please help

I noticed your comments next to maestro.restartScript(0). Yes, by changing the ‘0’ parameter, you are telling the Maestro which subroutine to restart at. (This is explained inside the comments at the bottom of Script.ino.)

If you are still not able to get started, please post your current Maestro script.

-Jon

Thank you for reply. I will test it soon. I have adafruit 16 channel servo board and asked them for help and they cant even help me. Their own product so sad that I wasted money on that product. Your products is the best.

I have finished my project on Mini Maestro 12-Channel USB Servo Controller. Thank you for your support Pololu, Here are the link for video. https://youtu.be/3nBgOJGafDA

Cool video. Thanks for sharing!

-Jon