In order to call a subroutine you have to create it manually with the Pololu Software and then Save all the secuences to script so the program haves something to call.
Command used: "Restart Script at Subroutine" with Pololu protocol http://www.pololu.com/docs/0J40/5.f
Pololu protocol: 0xAA, device number, 0x27, subroutine number
Each underlined is a byte that you must send, so in this case you send 4 bytes (4 packages of 1 byte), let's see how it works
Pololu protocol: 0xAA, device number, 0x27, subroutine number
Each underlined is a byte that you must send, so in this case you send 4 bytes (4 packages of 1 byte), let's see how it works
Arduino Code, Pololu protocol: "subroutine" is a method that do all the work
void sub(unsigned int subrutine)
{
Serial.write(0xAA); //start byte, Mandatory [byte 1]
Serial.write(0x0C); //device id or number (seen in part 1/3) [byte 2]
Serial.write(0x27); //command number, Mandatory [byte3]
if(subrutine == 0){
Serial.write(0x00); //execute subrutine number received [byte 4]
}
if(subrutine == 2){
Serial.write(0x02); //execute subrutine number received[byte 4]
}
if(subrutine == 3){
Serial.write(0x03); //execute subrutine number received[byte 4]
}
if(subrutine == 4){
Serial.write(0x04); //execute subrutine number received[byte 4]
}
}
{
Serial.write(0xAA); //start byte, Mandatory [byte 1]
Serial.write(0x0C); //device id or number (seen in part 1/3) [byte 2]
Serial.write(0x27); //command number, Mandatory [byte3]
if(subrutine == 0){
Serial.write(0x00); //execute subrutine number received [byte 4]
}
if(subrutine == 2){
Serial.write(0x02); //execute subrutine number received[byte 4]
}
if(subrutine == 3){
Serial.write(0x03); //execute subrutine number received[byte 4]
}
if(subrutine == 4){
Serial.write(0x04); //execute subrutine number received[byte 4]
}
}
void loop()
{
subroutine(3); // Calling subroutine number 3 (first is 0)
delay(1000); // Wait 1000 miliseconds (1 sec)
subroutine(4); // Calling subroutine number 4
delay(1000); // Wait 1000 miliseconds (1 sec)
No hay comentarios:
Publicar un comentario