HELP!! AYUDA!!


i need help.
i'm arduino project. must control dc motor pushbuttons. 1 of these must turn engine on , off (in code pin 2). push button must accelerate speed (pin 24) , other 1 must decelerate (pin26). code not work.

(estoy con un proyecto de arduino . debo controlar un motor dc con pulsadores. uno de estos debe encender y apagar el motor (en el codigo es el pin 2). otro pulsador debe acelerar la velocidad (pin 24) y el otro debe desacelerar (pin26). pero mi codigo no funciona)

const int control = 9; //motor
const int detener = 2; //stop
const int morespeed = 24;
const int lessspeed = 26;

volatile int speed=0;
volatile int estado=0;
long t0 = 0;

void controlar();

void setup()
   {   
    pinmode(control,  output);
    pinmode(detener, input);
    pinmode(morespeed, input);
    pinmode(lessspeed, input);

    attachinterrupt(0,controlar, rising);
   }

void loop()
   {

    if(estado == 1)
    {
      speed = 128;
      analogwrite(control, speed);
      delay(30);
    }
     if(estado == 0)
    {
      speed = 0;
      analogwrite(control, speed);
      delay(30);
    }

    if(digitalread(morespeed) == high)
    {
      speed = speed + 26;
      if(speed > 230)
        {speed = 230;}
      analogwrite(control, speed);
      delay(30);
    }

    if(digitalread(lessspeed) == high)
    {
      speed = speed - 26;
      if(speed < 26)
        {speed = 26;}
      analogwrite(control, speed);
      delay(30);
    }

   }

void controlar()
   {
    if(millis() > t0  + 150)
    {
      if(estado == 0)
      {
       estado=1;
      }
      else if(estado == 1)
      {
       estado=0;
      }
      t0=millis();
     }
   }
   

i appreciate help! (apreciaría mucho la ayuda!)

but code not work.
what do?

and please modify post , use code button </>
code: [select]
so code looks this , easy copy text editor. see how use forum

in general if want responsive program not use delay(). have @ how millis() used manage timing without blocking in several things @ time

i suspect need read buttons , save values in variables. function control motor can take account of saved values. may hep have variable record state of motor - stopped, accelerating, maxspeed, decelerating.

...r
planning , implementing program


Arduino Forum > Using Arduino > Programming Questions > HELP!! AYUDA!!


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts