Hello all,
I am working on a sketch that involve a PS3 move navigation controller paired with a Bluetooth dongle, inserted into a USB host shield, mounted on the Mega 2560.
What i would like to do is to have one of the pin on the Mega to go HIGH (lets say pin 22) when my sketch is showing "Wait For Incoming Connection Request" on the serial monitor (technically when my sketch boot up and is ready to connect to the PS3 controller)
Also I would want another pin to turn high (24 for this one) when my sketch shows "Navigation Controller Enabled" after that my PS3 controller have been successfully powered up and connected.
There is no place in the sketch itself that have a command line that generate those messages on the serial monitor, so I am guessing that they are coming from the included libraries...
So my question, is there a way to create an action (turning output pin HIGH) from a specific phrase that is being sent to the serial monitor?
Any help would be greatly appreciated,
Serge Landry
#include <PS3BT.h>
#include <SPI.h>
USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd);
void setup()
{
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"));
pinMode(22, OUTPUT);
pinMode(24, OUTPUT);
}
void loop()
{
Usb.Task();
if (PS3.PS3Connected || PS3.PS3NavigationConnected)
{
if (PS3.getAnalogHat(LeftHatX) > 150 || PS3.getAnalogHat(LeftHatX) < 110 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 100)
{
Serial.print(F("\r\nLeftHatX: "));
Serial.print(PS3.getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: "));
Serial.print(PS3.getAnalogHat(LeftHatY));
}
// Analog button values can be read from almost all buttons
if (PS3.getAnalogButton(L2))
{
Serial.print(F("\r\nL2: "));
Serial.print(PS3.getAnalogButton(L2));
}
if (PS3.getButtonClick(PS))
{
Serial.print(F("\r\nPS"));
PS3.disconnect();
}
else
{
if (PS3.getButtonClick(CIRCLE))
Serial.print(F("\r\nCircle"));
if (PS3.getButtonClick(CROSS))
Serial.print(F("\r\nCross"));
if (PS3.getButtonClick(UP))
Serial.print(F("\r\nUp"));
if (PS3.getButtonClick(RIGHT))
Serial.print(F("\r\nRight"));
if (PS3.getButtonClick(DOWN))
Serial.print(F("\r\nDown"));
if (PS3.getButtonClick(LEFT))
Serial.print(F("\r\nLeft"));
if (PS3.getButtonClick(L1))
Serial.print(F("\r\nL1"));
if (PS3.getButtonClick(L3))
Serial.print(F("\r\nL3"));
}
}
}