Hi guys,
So yea basically I want to know how I can use a delay command in my sketch but I want the other commands/lines to continue working as normal, because a normal delay will stop other functions from carrying on… so here’s my sketch (I have added a comment where the delay is in the void loop section)
/*
Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/
#include <PS3BT.h>
#include <Servo.h>
Servo manzoorsServo;
Servo manzoorsSpeedController;
Servo manzoorsSpeedControllerHover;
USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
PS3BT PS3(&Btd); // This will just create the instance
//PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
int servoPin = 8;
int speedController = 9;
int sCH = 6;
int b = 100;
int d = 70;
int ledPin = 7; // the number of the 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 is the command I need working vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
if(PS3.getButtonClick(LEFT))
{
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
}
//I basically want this above command working within this sketch which I know it wont as it currently is. ^^^^^^^^^^^^^^^^^^
if(PS3.getButtonClick(PS)) {
manzoorsSpeedControllerHover.write(100);
manzoorsSpeedController.write(d);
manzoorsServo.write(115);
ledState = LOW;
PS3.disconnect();
}
}
}
Any help would be really appreciated, thanks!