Powering DC motor behaviour. help please


ok guys i've modified code make work. (i've used leds acting relay.)

first/original state        off  off  on   =  motor off
button-a press              off  on   on   =  motor on forward
button-b press              off  off  on   =  motor off
   delay 5 seconds then     on   off  off  =  motor on reverse
button-c press              off  off  off  =  motor off
   delay 2 seconds then     off  off  on   =  (original state)

now, know how can ignore c_button while motor moving forward, , ignore b_button while motor moving in reverse? thanks.


code: [select]
// constant won't change:
const int  buttonpin = 2;    // pin pushbutton attached to
const int  b_buttonpin = 4;
const int  c_buttonpin = 8;

const int ledpin = 13;       // pin led attached to
const int b_ledpin = 12;
const int c_ledpin = 11;


// variables change:
int buttonpushcounter = 1;   // counter number of button presses
int buttonstate = 0;         // current state of button
int lastbuttonstate = 0;     // previous state of button

int b_buttonpushcounter = 1;   // counter number of button presses
int b_buttonstate = 0;         // current state of button
int b_lastbuttonstate = 0;     // previous state of button

int c_buttonpushcounter = 0;   // counter number of button presses
int c_buttonstate = 0;         // current state of button
int c_lastbuttonstate = 0;     // previous state of button

void setup() {
  // initialize button pin input:
  pinmode(buttonpin, input);
  pinmode(b_buttonpin, input);
  pinmode(c_buttonpin, input);
  // initialize led output:
  pinmode(ledpin, output);
  pinmode(b_ledpin, output);
  pinmode(c_ledpin, output);
  // initialize serial communication:
  serial.begin(9600);
}


void loop() { //first

  buttonstate = digitalread(buttonpin);
  b_buttonstate = digitalread(b_buttonpin);
  c_buttonstate = digitalread(c_buttonpin);

 
  if (buttonstate != lastbuttonstate)
      { delay (50);  if (buttonstate == high)
                  {  b_buttonpushcounter++;
                     // serial.println("on");
                     // serial.print("number of button pushes:  ");
                     // serial.println(buttonpushcounter);
                  }
    else  {    serial.println("forward");
          }
      }
 
 
  if (b_buttonstate != b_lastbuttonstate)
        {  delay (50);  if (b_buttonstate == high)
                  {  b_buttonpushcounter++,
                     c_buttonpushcounter++;
         
                     serial.println("motor off");
                     // serial.print("number of b_button pushes:  ");
                     //serial.println(b_buttonpushcounter);
                  }
    else  {   delay(4000);
              serial.println("reversing");
              buttonpushcounter++;
          }
  }

   if (c_buttonstate != c_lastbuttonstate)
        {  delay (50);  if (c_buttonstate == high)
                  {  buttonpushcounter++;
                     serial.println("motor off");
                     //serial.print("number of c_button pushes:  ");
                     //serial.println(c_buttonpushcounter);
                  }
    else  {    serial.println("original state");
               delay(1000);c_buttonpushcounter++;
          }
  }


    lastbuttonstate = buttonstate;
   
  if (buttonpushcounter % 2 == 0)
           {  digitalwrite(ledpin, high);
           }
  else     {  digitalwrite(ledpin, low);
           }



    b_lastbuttonstate = b_buttonstate;
   
  if (b_buttonpushcounter % 2 == 0)
           {  digitalwrite(b_ledpin, high);
           }
  else     {  digitalwrite(b_ledpin, low);
           }
           
    c_lastbuttonstate = c_buttonstate;
   
  if (c_buttonpushcounter % 2 == 0)
           {  digitalwrite(c_ledpin, high);
           }
  else     {  digitalwrite(c_ledpin, low);
           }

} // end

have tried compiling code?


Arduino Forum > Using Arduino > Project Guidance > Powering DC motor behaviour. help please


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

Rasperry Wifi LAN Controller - Raspberry Pi Forums

Unlock car with bluetooth and car key