hi people could do with abit of help.......

i have this

int toy_value[2] = {0,0}; and what i would like to do is store the same values in a variable so that i can do this......

pulse = (toy_value - toy_variable)

the toy_veriable would be 1 loop behide

my question is.......

How do i store as a veriable and how do i recall the data ?

any help would be most greatful :-)

If you make your variables global (declared outside of "loop") they will have scope that will persist between calls to "loop".

If you're trying to do what I think you are, this is what you're looking for:

int toy_value[2] = {0,0};
int pulse = 0;
void loop() {
  toy_value[0] = digitalRead(2);
  pulse =  (toy_value[0] - toy_value[1]);
  toy_value[1] = digitalRead(2); //store state
  //pulse will indicate a change at pin 2 since last loop
  if (pulse==1) {/*going high*/}
  else if (pulse==-1) {/*going low*/}
    other code here

im trying to do this…

int ver;

    for (int s=0; s<1; s++)
   step_value[s] = accel[1];   

  pulse_value[0] = step_value[0];
  step_value[3] =  (pulse_value[0]-pulse_value[1]);
  pulse_value[1] = step_value[0]; 
  if (step_value[3]==-1) 
  digitalWrite(dirpin, HIGH);
  else if (step_value[3]==1) 
  digitalWrite(dirpin, LOW); 

 {ver = 0;
   while(ver < (step_value[3]*1.))
  digitalWrite(steppin, LOW);
  digitalWrite(steppin, HIGH); 

but my stepper is very jumpy and in ramdom directoin…

can anybody help??? :slight_smile: