Hardware Reference
In-Depth Information
}
else if(color_bit=='B'){
lightsequence_blue();
}
2.
When the character is received, the corresponding light sequence is turned on.
Control of stepper via serial port
1.
Earlier, we discussed the control of the stepper motor using a power Darlington driver
and the control rouine for one full rotaion. In this secion, we will discuss how to
control the direcion and the number of steps based on the input from the serial
port. In this example, the clockwise direcion is indicated by + , and counterclockwise
direcion is indicated by - .
For example, in order to move 45 steps in a clockwise direction, the command
would be +45 preceded by the letter P . Hence, it would be P+45 . Similarly, the
counterclockwise direction command would be P-45 :
if( serial_read == 'P' ) {
while(Serial.available())
{
sb = Serial.read();
serInString[serInIndx] = sb;
serInIndx++;
}
}
2.
We await the serial character P and store the rest of the string in a buffer. Once the
data is stored in the buffer, we will determine whether the first character is + or - .
The ASCII number for the + sign is 43 and 45 for the - sign. We compare the
first character in the buffer and execute the command accordingly. Serial
communications usually transmit ASCII numbers and hence the numbers
are converted into their decimal equivalents:
if(serInString[0]==43){
int var_serial=0;
for(serOutIndx=1;serOutIndx<serInIndx;serOutIndx++)
{
var_serial = var_serial*10+(serInString[serOutIn
dx]-48);
}
motorSpeed=20;
for(int i=0;i<var_serial;i++){
clockwise();
}
 
Search WWH ::




Custom Search