press button stepper moved 360 steps

Hi Guys/Girls, I am a total noob here and have read and tried to understand what I have done wrong here and cant figure it out, if you are able to hep it is much appreciated.
the code:

#include <AccelStepper.h>
int ButtonA;
AccelStepper stepper(1, 9, 10); //pin 9step, pin10 direction
int pos = 360;
int ButtonAState = 0;


void setup() 
{                
  pinMode(4,INPUT);
  //pinMode(5,INPUT);
  pinMode(10, OUTPUT);     //10 is direction
  pinMode(9, OUTPUT);    //9 is step
  stepper.setMaxSpeed(5000);
  stepper.setSpeed(50);  
  stepper.setAcceleration(9000000);
}

void loop(){
  
val = digitalRead(ButtonA); //Reads state of button
//Check if button is pressed 
if (val == HIGH) {
 stepper.runToNewPosition(pos);
 
 delay(50);
 
}

I am trying to make the stepper turn 360 steps each tiem buttonA is pressed.
thanks.

Read

  1. the how to use this forum sticky to learn how to post code.
  2. the documentation on the accel libary - when using it you are supposed to make repeated calles to a function until the motor has got to its correct position. You will need a while loop inside your if statement to do this.

Rodger that, thanks for the help

I'm not asking for help with how to get a stepper to move, I have that working, I am asking for help to tie this to a momentary switch

thx

You are just looking at the level from the switch. You need to look at the edge. That is when the button changes from a low to a high.
To do this store the previous value of the button and only move the motor when the current value is high and the previous value was low.
Look in the IDE for an example called change.

Thank you mate, will do.