How do I use a delay within a sketch loop which will not disrupt other commands?


hi guys,

so yea want know how can use delay command in sketch want other commands/lines continue working normal, because normal delay stop other functions carrying on.. here's sketch (i have added comment delay in void loop section)

code: [select]
/*
 example sketch ps3 bluetooth library - developed kristian lauszus
 for more information visit blog: http://blog.tkjelectronics.dk/ or
 send me e-mail:  kristianl@tkjelectronics.com
 */

#include <ps3bt.h>
#include <servo.h>
servo manzoorsservo;
servo manzoorsspeedcontroller;
servo manzoorsspeedcontrollerhover;

usb usb;
btd btd(&usb); // have create bluetooth dongle instance so
/* can create instance of class in 2 ways */
ps3bt ps3(&btd); // create instance
//ps3bt ps3(&btd,0x00,0x15,0x83,0x3d,0x0a,0x57); // store bluetooth address - can obtained dongle when running sketch

// follow variables long because time, measured in miliseconds,
// become bigger number can stored in int.
int servopin = 8;
int speedcontroller = 9;
int sch = 6;
int b = 100;
int d = 70;
int ledpin =  7;      // number of led pin

void setup()

  { 
    pinmode(ledpin, output);
    manzoorsservo.attach(servopin);
    manzoorsspeedcontroller.attach(speedcontroller);
    manzoorsspeedcontrollerhover.attach(sch);
  {
    serial.begin(115200);
    if (usb.init() == -1) {
    serial.print(f("\r\nosc did not start"));
    while(1); //halt
  }
    serial.print(f("\r\nps3 bluetooth library started"));
 }
}
 
void loop() {
  usb.task();
 
  if(ps3.ps3connected || ps3.ps3navigationconnected)
 
       {
       manzoorsservo.write(map(ps3.getanaloghat(righthatx), 0, 255, 0, 120));
       }
       else
       {
       manzoorsservo.write(115);
       }
       
       if(ps3.ps3connected || ps3.ps3navigationconnected)
       {
                                                                               
       manzoorsspeedcontroller.write(map(ps3.getanalogbutton(r2_analog), 0, 255, 50, 135));
       
       manzoorsspeedcontrollerhover.write(map(ps3.getanalogbutton(l2_analog), 0, 255, 100, 160));
       
       //below command need working vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
       if(ps3.getbuttonclick(left))
       {
         digitalwrite(7, high);
         delay(300);
         digitalwrite(7, low);
       }
       //i want above command working within sketch know wont is. ^^^^^^^^^^^^^^^^^^
       
       if(ps3.getbuttonclick(ps)) {
       manzoorsspeedcontrollerhover.write(100);
       manzoorsspeedcontroller.write(d);
       manzoorsservo.write(115);
       ledstate = low;
       ps3.disconnect();
       }
      }
     }


any appreciated, thanks!

look @ "blink without delay" example in ide, without delay


Arduino Forum > Using Arduino > Project Guidance > How do I use a delay within a sketch loop which will not disrupt other commands?


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code