Ok here's my code, please see the commented out part "where I'm lost".
Thanks again.
/*
Nano | TPIC6B595
5V | 2 (VCC)
GND | GND
D8 | 8 (SRCLR)
D10 | 12 (RCK)
D11 | 3 (SER IN) of the first chip
D13 | 13 (SRCK)
| 9 to GND
| 10, 11,19 to GND
| 18 (SER OUT) to 3 of the next chip
*/
#include <SPI.h>
#include <EEPROM.h>
const byte motors = 41; // sets of four motors
const byte clrPin = 8; // TPIC6B595 SRCLR pin8
const byte latchPin = 10; // TPIC6B595 RCK pin12
int CurrPos; // current position
int NewPos; // new position to go to
int RandNum; // random number
int steps; // will hold number of steps to reach a target position
int sensor = 2; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)
int TargetPos[] = {550, 1900, 3080, 2048, 5000, 5500, 6028, 7500}; // hypotetical positions, just for testing
void setup() {
SPI.begin();
pinMode(clrPin, OUTPUT);
pinMode(latchPin, OUTPUT);
digitalWrite(clrPin, HIGH); // clear all shift register data
EEPROM.get( 0, CurrPos ); // read tha last known position of the steppers
}
void loop() {
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
Go_To_Target_Pos();
}
}
void Go_To_Target_Pos() {
randomSeed(analogRead(0)); // generate a random number
RandNum = random(0, 7); // a numbers equal to numer of positions in array TargetPos
delay(50);
NewPos = (TargetPos[RandNum]);
steps = (NewPos - CurrPos); // number of steps needed to go from current position to new position
if (steps < 0) {
steps = steps * - 1; // go backwards
}
/* **********************************************
>>>>>> Here's where I'm lost <<<<<<<<<<
without shift registers I'd write direction pin HIGH/LOW to go forward
or backward, then :
for (int x = 0; x < steps + 1; x++) {
digitalWrite(step_pin, HIGH);
delay(10);
digitalWrite(step_pin, LOW);
}
>>>>> Using shift registers what is the procedure to send the correct bits
to all shift registers to meve all steppers to the NewPos ?
***********************************
*/
EEPROM.update(0, NewPos);
state = LOW; // update variable state to LOW
}