Hi all,
I have one problem, I'm using Arduino Mega and reading signal from my digital I/O. After that i want to switch a motor rotary direction when the signal is HIGH, but the switching goes one cycle later... I mean when i have LOW on Digital Input goes forward and when i get HIGH goes one cycle forward and then goes backward...
//The code to start shifting!
//The software is quite simple. You will need to create a register of 8 bits and shift it in when you want to update the actual register. The sample code blow illustrates a simple example which you can copy and paste into your project.
///////////////////////////////////
int DS_pin = 8;
int STCP_pin = 12;
int SHCP_pin = 4;
int EN_pin = 7;
int Speed_pin = 11;
int Sensor_pin = 24;
int var;
//boolean val = digitalRead(Sensor_pin);
void setup()
{
pinMode(DS_pin,OUTPUT);
pinMode(STCP_pin,OUTPUT);
pinMode(SHCP_pin,OUTPUT);
writereg();
pinMode(EN_pin,OUTPUT);
pinMode(Speed_pin,OUTPUT);
pinMode(Sensor_pin,INPUT);
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println(digitalRead(Sensor_pin)); //for visualization delay(10); } } //his is an electrical problem, no software issue I presume. //Here is how to proceed: 1) Make sure both boards have the //same ground (connect GND together and make sure there is //no conflict) 2) Connect your output to an input on the //Arduino board (pin 2 e.g.). This connection is preferably //done using a resistor, 1 kOhm will be ok. //On software side, just set this pin as input //pinMode(2,INPUT); in setup() and then get its value //status = digitalRead(2); in loop().
Why are you waiting a full second between the time you call 'Forward()' to set values in 'registers' and the time you use 'writereg()' to send the data out?
Why are you waiting a full second between the time you call 'Forward()' to set values in 'registers' and the time you use 'writereg()' to send the data out?
Because when i use delay after Forward it give me how long the motor will go forward... But that isn't the problem.
The problem is when I get 0 from my Sensor_pin , motor goes forward and when I get 1 goes forward again and then goes backward, which I seem unusual.