I have had this sketch working on another project where there are direction buttons.
If I rem out first loop, the motor turns as it should and if I rem out the second loop the motor turns okay the other way. However if I put the two loops in the sketch the motor does not move?
I do not get any error messages
Can someone tell me why? Thanks
//FINAL CAMERA RECEIVER
//HC12CAMERATX
#include <SoftwareSerial.h>
int i;
//declare variables for the motor pins
int motorPin1 = 9; // Blue - 28BYJ48 pin 1
int motorPin2 = 10; // Pink - 28BYJ48 pin 2
int motorPin3 = 11; // Yellow - 28BYJ48 pin 3
int motorPin4 = 12; // Orange - 28BYJ48 pin 4
int motorSpeed = 3500;
int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
void setup()
{
//Serial.begin(9600);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}
void loop()
{
for (int i = 0; i < 8; i++) // clockwise
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
for (int i = 8; i >= 0; i--) // anticlockwise
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}
void setOutput(int out)
{
digitalWrite(motorPin1, bitRead(lookup[out], 0));
digitalWrite(motorPin2, bitRead(lookup[out], 1));
digitalWrite(motorPin3, bitRead(lookup[out], 2));
digitalWrite(motorPin4, bitRead(lookup[out], 3));
}
EDIT: Since checked, the loops are working, but the motor will not run one way then the other with two loops. Either single loop will make motor go forward or backwards.