Hi, I'm building a turntable for photo scanning.
I would need help with coding. I have a DRV8825 that controls a stepper motor
What I want to do is when i push a button, stepping motor (50BYJ46-6) spins 360 degrees but to stop x number of times to take a picture with a camera. Idea is to later implement this to a menu that i found online that i have used before in a different project and have three diffrent tabs where one stop 24 times second tab where it stop 36 times and a third stops 48 times.
Camera taking picture part i already know what to do.
Here is some code that I have started with. The result that i have now is that it moves once and not 360.
blackpower, greenpower is two mosfet that i use to cut the power(12v and 5v) from the drv8825 so when it's in idle the stepping motor doesn't get warm.
#include <AccelStepper.h>
#include "sixteen.h"
void setup()
{
stepper.setMaxSpeed(1000);
pinMode(blackpower, OUTPUT);
pinMode(greenpower, OUTPUT);
}
void loop() {
motor_sixteen();
delay(10000);
}
#define dirPin 4
#define stepPin 3
#define motorInterfaceType 1
int blackpower = 7;
int greenpower = 8;
#include "pins.h"
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
bool fHasLooped = false;
void motor_sixteen() {
if ( fHasLooped == false )
{
stepper.setCurrentPosition(0);
// Run the motor forward at 200 steps/second until the motor reaches 400 steps (2 revolutions):
while (stepper.currentPosition() != 400)
{
for ( int x = 0; x < 10; x++ )
{
stepper.setSpeed(200);
stepper.runSpeed();
}
fHasLooped = true;
}
}
}
Here is the menu
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int upButton = 5;
int downButton = 7;
int selectButton = 6;
int menu = 1;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(1, 0);
lcd.print("TURNTABLE");
delay(5000);
lcd.clear();
Serial.begin(9600);
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(selectButton, INPUT_PULLUP);
updateMenu();
}
void loop() {
if (!digitalRead(downButton)){
menu++;
updateMenu();
delay(100);
while (!digitalRead(downButton));
}
if (!digitalRead(upButton)){
menu--;
updateMenu();
delay(100);
while(!digitalRead(upButton));
}
if (!digitalRead(selectButton)){
executeAction();
updateMenu();
delay(100);
while (!digitalRead(selectButton));
}
}
void updateMenu() {
switch (menu) {
case 0:
menu = 1;
break;
case 1:
lcd.clear();
lcd.print(">16");
lcd.setCursor(0, 1);
lcd.print(" 24");
break;
case 2:
lcd.clear();
lcd.print(" 24");
lcd.setCursor(0, 1);
lcd.print(">36");
break;
case 3:
lcd.clear();
lcd.print(" 36");
lcd.setCursor(0, 1);
lcd.print(">Settings");
break;
case 4:
menu = 3;
break;
}
}
void executeAction() {
switch (menu) {
case 1:
action1();
break;
case 2:
action2();
break;
case 3:
action3();
break;
case 4:
action4();
break;
}
}
void action1() {
lcd.clear();
lcd.print(">SCAN");
delay(2500);
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("SCANNING");
delay(1000);
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("DONE");
delay(500);
}
void action2() {
lcd.clear();
lcd.print(">SCAN");
delay(2500);
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("SCANNING");
delay(1000);
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("DONE");
delay(500);
}
void action3() {
lcd.clear();
lcd.print(">SCAN");
delay(2500);
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("SCANNING");
delay(1000);
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("DONE");
delay(500);
}
void action4() {
lcd.clear();
lcd.print(">Bluetooth");
delay(2500);
digitalWrite(13, HIGH);
delay(4000);
digitalWrite(13, LOW);
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("ON/OFF");
delay(500);
}
