#include <AFMotor.h>
int xmove = 12;
int ymove = 5;
int xrpm = 150;
int yrpm = 150;
int j = 1;
int Button[9][3] = {{1, 705, 715},
{2, 735, 745},
{3, 830, 840},
{4, 845, 860},
{5, 600, 620},
{6, 640, 670},
{7, 300, 320},
{8, 445, 460},
{9, 260, 265},
};
int analogpin = 0;
int label = 0;
int counter = 0;
long time = 0;
int debounce_count = 50;
int current_state = 0;
int ButtonVal;
int column=8;
int row=50;
int row_count;
int column_count;
double movement;
int pause = 2800;
int frames=0;
int count = 0;
AF_Stepper motor1(100, 1);
AF_Stepper motor2(100, 2);
void setup()
{
Serial.begin(9600);
motor1.setSpeed(yrpm);
motor2.setSpeed(xrpm);
}
void loop()
{
if (millis() != time)
{
ButtonVal = analogRead(analogpin);
if(ButtonVal == current_state && counter >0)
{
counter--;
}
if(ButtonVal != current_state)
{
counter++;
}
if (counter >= debounce_count)
{
counter = 0;
current_state = ButtonVal;
if (ButtonVal > 0)
{
ButtonCheck();
}
}
time = millis();
}
}
void ButtonCheck()
{
for(int i = 0; i <= 21; i++)
{
if(ButtonVal >= Button[i][j] && ButtonVal <= Button[i][j+1])
{
label = Button[i][0];
Action();
}
}
}
void Action()
{
if(label == 1)
{
Serial.println("Button 1");
motor1.step(xmove, FORWARD, DOUBLE);
}
if(label == 2)
{
Serial.println("Column =");
column++;
Serial.println(column);
}
if(label == 3)
{
Serial.println("Button 2");
motor1.step(xmove, BACKWARD, DOUBLE);
}
if(label == 4)
{
Serial.println("Initiated");
row_count=1;
movement=1;
column_count=1;
frames= row * column;
while(count<= frames){
if( movement==1){
while(column_count <= column){
motor1.step(xmove, FORWARD, DOUBLE);
Serial.println(column_count);
Serial.println(movement);
delay(pause);
count++;
column_count++;
}
}
if( movement!= 1){
while(column_count >= 1){
motor1.step(xmove, BACKWARD, DOUBLE);
Serial.println(column_count);
Serial.println(movement);
delay(pause);
count++;
column_count--;
}
}
if (column_count==column+1){
if(movement == 1){
motor2.step(ymove, BACKWARD, DOUBLE);
Serial.println(column_count);
Serial.println(movement);
delay(pause);
count++;
column_count = column;
movement = movement * (-1);
row_count++;
motor1.step(xmove-2, BACKWARD, DOUBLE);
Serial.println(column_count);
Serial.println(movement);
delay(pause);
count++;
column_count--;
}
}
if (column_count == 0){
if(movement ==- 1){
motor2.step(ymove, BACKWARD, DOUBLE);
Serial.println(column_count);
Serial.println(movement);
delay(pause);
count++;
column_count =1 ;
row_count++;
movement=1;
}
}
}
}
if(label == 5)
{
Serial.println("Button 3");
motor2.step(ymove, FORWARD, DOUBLE);
}
if(label == 6)
{
Serial.println("Row =");
row++;
Serial.println(row);
}
if(label == 7)
{
Serial.println("Button 4");
motor2.step(ymove, BACKWARD, DOUBLE);
}
if(label == 8)
{
Serial.println("reset");
}
if(label == 9)
{
Serial.println("switch");
}
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.