// STARTRACKER MOTOR CONTROL: STEPPER MOTOR CONTROL FOR JJROBOTS POV DISPLAY
// This code is designed for JJROBOTS arDusplay Stepper Motor Control board
// Author: JJROBOTS.COM (Jose Julio & Juan Pedro)
// Licence: GNU GPL
// Stepper : NEMA17
// Driver : A4988 or DRV8825
// Microstepping : configured to 1/16
// Arduino board: Pro micro (leonardo equivalent)
// STEPPER DRIVER CONNECTED TO:
// ENABLE pin: D10 (PB6)
// DIR pin: D9 (PB5)
// STEP pin: D8 (PB4)
// Button1 : START/STOP D4
// Button2 : DEC D5
// Button3 : CHANGE ROTATION DIRECTION (go back to original position) D6
//DO NO TAKE PHOTOS WITH AN EXPOSITION LONGER THAN 5 MINUTES. THE DRIFT WOULD BE NOTICEABLE.
//Theory behind this CODE
//-----------------------------------------
// 360º (rotation of the Earth every 1436min)
// *Using a M8 rod coming up 1.25mm every complete rotation
#define COMINGUPSPEED 1.25 //milimeters that the rod comes up every complete rotation (360º). In a M8 rod/bolt is usually 1.25 mm. In a M6, only 1.00mm
//other info needed:
//ratio between the large gear and the small one=0.2549
//MEASURE THIS VALUE AS GOOD AS YOU CAN AND SET THE LENGHT BELOW
#define LENGTH 228 //distance from the centre of the hinge to the centre of the hole for the rod in milimiters
// Calculus here:
#define STEP ((2*3.14159)/1436)*LENGTH //rotational velocity of the small gear
#define RPS (STEP/(60*0.2549))/COMINGUPSPEED //rotational velocity of the large gear
#define ZERO_SPEED 65535
#define STEPS_PER_REV 3200 // 200 steps motor with 1/16 microstepping