// Sketch for CamSlider
// 06/04/2019 by RZtronics <raj.shinde004@gmail.com>
// Project homepage: http://RZtronics.com/
///
//Terms of use
///
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
///
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
#include "bitmap.h"
#define limitSwitch 11
#define PinSW 2
#define PinCLK 3
#define PinDT 8
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
AccelStepper stepper2(1, 7, 6); // (Type:driver, STEP, DIR)
AccelStepper stepper1(1, 5, 4);
MultiStepper StepperControl;
long gotoposition[2];
volatile long XInPoint=0;
volatile long YInPoint=0;
volatile long XOutPoint=0;
volatile long YOutPoint=0;
volatile long totaldistance=0;
int flag=0;
int temp=0;
int i,j;
unsigned long switch0=0;
unsigned long rotary0=0;
float setspeed=200;
float motorspeed;
float timeinsec;
float timeinmins;
volatile boolean TurnDetected;
volatile boolean rotationdirection;
void Switch()
{
if(millis()-switch0>500)
{
flag=flag+1;
}
switch0=millis();
}
void Rotary()
{
delay(75);
if (digitalRead(PinCLK))
rotationdirection= digitalRead(PinDT);
else
rotationdirection= !digitalRead(PinDT);
TurnDetected = true;
delay(75);
}
void setup()
{
Serial.begin(9600);
stepper1.setMaxSpeed(3000);
stepper1.setSpeed(200);
stepper2.setMaxSpeed(3000);
stepper2.setSpeed(200);
pinMode(limitSwitch, INPUT_PULLUP);
pinMode(PinSW,INPUT_PULLUP);
pinMode(PinCLK,INPUT_PULLUP);
pinMode(PinDT,INPUT_PULLUP);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay()