Je désire arrêter un moteur pas a pas alors qu'il est en rotation.
Voici le programme que j'utilise côté arduino, les instructions de rotation et arrêt sont envoyées depuis un programme java exécuté sur le pc et transmis en série.
- Code: Tout sélectionner
/*
Mega multple serial test
Receives from the main serial port, sends to the others.
Receives from serial port 1, sends to the main serial (Serial 0).
This example works only on the Arduino Mega
The circuit:
* Any serial device attached to Serial port 1
* Serial monitor open on Serial port 0:
created 30 Dec. 2008
by Tom Igoe
This example code is in the public domain.
*/
#include <Wire.h>
#include <snootor.h>
SnootorStep M;
void setup() {
// initialize both serial ports:
Serial.begin(9600);
//Serial1.begin(9600);
Wire.begin();
M.init(2000,100,1,MOTOR_MODE_HALFSTEP);
}
void loop() {
// read from port 1, send to port 0:
M.setMode(MOTOR_MODE_HALFSTEP);
if (Serial.available()) {
String phrase="";
int inByte = Serial.read();
// while (inByte!=13)
// {
// phrase += char(inByte);
// inByte = Serial.read();
// }
switch (inByte){
case 'p':
M.stop();
M.forward(2000);
while(!M.stopped()){
SC.delay(200);
SC.dump();
}
break;
case 'm':
M.stop();
M.back(2000);
while(!M.stopped()){
SC.delay(200);
SC.dump();
}
break;
case 'a':
M.stop();
//M.back(2000);
//SC.delay(8000);
break;
}
delay(250);
Serial.write(inByte);
}
}
pouvez-vous m'indiquer comment procéder.
Cordialement à tous
Phoebus
