Hola a todos
De regreso con problemas controlando motores
A qui tengo este código que me funciona muy bien controlando un motor DC
/*
The code is written by Farshid Jafari Harandi,
(C) Spekel, Spekel.se y modificado por cuchara con ayuda del foro arduino
*/
int Revers =5; // boton de cambi de direccion
int ledPin = 13; // LED connected to digital pin 13
int pwmPin = 11; // PWM Motor driver (/D2 pin pin on MC338870 motor board)
int motorPin1 = 7; // Motor pin 1 (IN1 on MC338870 motor board)
int motorPin2 = 8; // Motor pin 2 (IN2 on MC338870 motor board)
int pot = 0; // Potentiometer pin on analog input 0
//Leave D1 and /FS and /FB unconnceted
//Connect the EN to +5V on Arduino board
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
int val;
// The setup() method runs once, when the sketch starts
void setup() {
pinMode(Revers, INPUT);
pinMode(ledPin, OUTPUT); // initialize the digital pin as an output:
pinMode(pwmPin, OUTPUT); // initialize the digital pin as an output:
pinMode(motorPin1, OUTPUT); // initialize the digital pin as an output:
pinMode(motorPin2, OUTPUT); // initialize the digital pin as an output:
digitalWrite(Revers,HIGH);
Serial.begin(9600);
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
reading = digitalRead(Revers);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(ledPin, state);
previous = reading;
val = analogRead(pot);
val = map(val,0,1023,-255,255);
Serial.println(val);
if (state){
if (val >= 0)
{
digitalWrite(ledPin,HIGH);
digitalWrite(motorPin1,LOW);
digitalWrite(motorPin2,HIGH);
analogWrite(pwmPin,val);
}
else
{
val *= -1;
digitalWrite(ledPin,LOW);
digitalWrite(motorPin1,HIGH);
digitalWrite(motorPin2,LOW);
analogWrite(pwmPin,val);
}
}
if (!state) {
if (val >= 0) {
digitalWrite(ledPin,HIGH);
digitalWrite(motorPin1,HIGH);
digitalWrite(motorPin2,LOW);
analogWrite(pwmPin,val);
}
else {
val *= -1;
digitalWrite(ledPin,LOW);
digitalWrite(motorPin1,LOW);
digitalWrite(motorPin2,HIGH);
analogWrite(pwmPin,val);
}
}
delay(100);
}
lo conecto así
Lo que estoy buscan y no consigo es obtener los mismos resultado controlando un motor paso a paso nema17
probe muchas modificaciones en el código pro no creo que sean de utilidad ya que no pasa nada
Espero me puedan ayudar
de antemano gracias