Hi there, I'm trying to build a machine that makes a dottet line.. ![]()
Got everythng set up and it's working mechanical.
But my coding is a problem..
I wanted to design the thing by creating a function for DCmotor1 (moving) and a seperate function for
DCmotor2 (dotting)
And then i could just make a loop referncing to those two functions.
While the functions work if they are the main loop, they wont work when as a function.
code below..
This works - but is not how it should work.
int debug = false;
const int controlLeft = 5;
const int controlRight = 3;
const int enablePinA = 6;
const int buttonPin = 8;
int button = HIGH;
int tapDutyCycle = 250; // 1000 = 100% || 100 = 10%
boolean motorOn = false;
boolean motorDirection = false;Â // false should be left
void setup()
{
 if (debug == true)
 {
  Serial.begin(9600);
 }
Â
 pinMode(controlLeft, OUTPUT);
 pinMode(controlRight, OUTPUT);
 pinMode(enablePinA, OUTPUT);
Â
 digitalWrite(enablePinA, LOW);
}
void loop()
{
  if (debug == true)
  {
   Serial.println("Tap");
  }
 digitalWrite(enablePinA, HIGH);
 digitalWrite(controlRight, HIGH);
 delayMicroseconds(tapDutyCycle);
 digitalWrite(controlRight, LOW);
 delayMicroseconds(1000 - tapDutyCycle);
Â
 digitalWrite(enablePinA, LOW);
}
This does not work, but is how i WANTED it to work..
I have added a button, to prevent the motor from running all the time.
int debug = false;
const int controlLeft = 5;
const int controlRight = 3;
const int enablePinA = 6;
const int buttonPin = 8;
int button = HIGH;
int tapDutyCycle = 250; // 1000 = 100% || 100 = 10%
boolean motorOn = false;
boolean motorDirection = false;Â // false should be left
void setup()
{
 if (debug == true)
 {
  Serial.begin(9600);
 }
Â
 pinMode(controlLeft, OUTPUT);
 pinMode(controlRight, OUTPUT);
 pinMode(enablePinA, OUTPUT);
Â
 digitalWrite(enablePinA, LOW);
}
void tap()
{
  if (debug == true)
  {
   Serial.println("Tap");
  }
 digitalWrite(enablePinA, HIGH);
 digitalWrite(controlRight, HIGH);
 delayMicroseconds(tapDutyCycle);
 digitalWrite(controlRight, LOW);
 delayMicroseconds(1000 - tapDutyCycle);
Â
 digitalWrite(enablePinA, LOW);
}
void loop()
{
button = digitalRead(buttonPin);
 if (debug == true)
 {
  Serial.print("Button state : ");
  Serial.print(button);
  Serial.println("");
  delay(50);
 }
while(button == HIGH);
{Â
  tap();
}
delay(500); // loop delayÂ
}
And i havent made the second function yet, since i cant get the first to run as intended.
Any ideas?