First, sorry about my English language, I am from Serbia.
Yesterday, I bought this little gem of software via SlideME. Installed all of necessary software, make my first example and get this result on my phone:
My code is as follows:
/* ===== pfod Command for Arcade control ====
{.<l><+2><b>Arcade control|P~<r><+1><b>Power is `0~~OFF\ON|L~<w><+1><b>Lights are `0~~OFF\ON|S~<l><+1><b>Sound is `0~~OFF\ON|Z~<y><+1><b>*****|C~<a><+1><b>Insert coin}
*/
// Using UART Serial running at 9600 for send and receive
// Serial D0 (RX) and D1 (TX) on Arduino Uno, Micro, ProMicro, Due, Mega, Mini, Nano, Pro and Ethernet
/* Code generated by pfodDesigner V1.2.521
* (c)2014 Forward Computing and Control Pty. Ltd.
* NSW Australia, www.forward.com.au
* This generated code may be freely used for both private and commerical use
*/
// ======================
// this is the pfodParser.h file with comments, constants and un-used methods removed
class pfodParser {
public:
pfodParser();
void init();
byte parse(byte in);
byte* getCmd();
byte* getFirstArg();
byte getArgsCount();
byte* parseLong(byte* idxPtr, long *result);
private:
byte argsCount; byte argsIdx; byte parserState; byte args[255];
};
//============= end of pfodParser.h
pfodParser parser; // create a parser to handle the pfod messages
// give the board pins names, if you change the pin number here you will change the pin controlled
int cmd_P_pin = 4; // name the output pin for 'Power is '
int cmd_L_pin = 5; // name the output pin for 'Lights are '
int cmd_S_pin = 6; // name the output pin for 'Sound is '
// the setup routine runs once on reset:
void setup() {
Serial.begin(9600);
for (int i=3; i>0; i--) {
// wait a few secs to see if we are being programmed
delay(1000);
}
//pinMode(cmd_P_pin, INPUT_PULLUP);
pinMode(cmd_P_pin, OUTPUT); // output for 'Power is ' is initially LOW, uncomment line above if you want it initially HIGH
//pinMode(cmd_L_pin, INPUT_PULLUP);
pinMode(cmd_L_pin, OUTPUT); // output for 'Lights are ' is initially LOW, uncomment line above if you want it initially HIGH
//pinMode(cmd_S_pin, INPUT_PULLUP);
pinMode(cmd_S_pin, OUTPUT); // output for 'Sound is ' is initially LOW, uncomment line above if you want it initially HIGH
// <<<<<<<<< Your extra setup code goes here
}
// the loop routine runs over and over again forever:
void loop() {
if (Serial.available()) {
byte in = Serial.read(); // read the next char
byte cmd = parser.parse(in); // pass it to the parser
// parser returns non-zero when a pfod command is fully parsed
if (cmd != 0) { // have parsed a complete msg { to }
byte* pfodFirstArg = parser.getFirstArg(); // may point to \0 if no arguments in this msg.
long pfodLongRtn; // used for parsing long return arguments, if any
if ('.' == cmd) {
// pfodApp has connected and sent {.} , it is asking for the main menu
// send back the menu designed
sendMainMenu();
// now handle commands returned from button/sliders
} else if('P'==cmd) { // user moved slider -- 'Power is '
// set output based on slider 0 == LOW, 1 == HIGH
parser.parseLong(pfodFirstArg,&pfodLongRtn); // parse first arg as a long
digitalWrite(cmd_P_pin,pfodLongRtn); // set output
sendMainMenuUpdate(); // always send back a pfod msg otherwise pfodApp will disconnect.
} else if('L'==cmd) { // user moved slider -- 'Lights are '
// set output based on slider 0 == LOW, 1 == HIGH
parser.parseLong(pfodFirstArg,&pfodLongRtn); // parse first arg as a long
digitalWrite(cmd_L_pin,pfodLongRtn); // set output
sendMainMenuUpdate(); // always send back a pfod msg otherwise pfodApp will disconnect.
} else if('S'==cmd) { // user moved slider -- 'Sound is '
// set output based on slider 0 == LOW, 1 == HIGH
parser.parseLong(pfodFirstArg,&pfodLongRtn); // parse first arg as a long
digitalWrite(cmd_S_pin,pfodLongRtn); // set output
sendMainMenuUpdate(); // always send back a pfod msg otherwise pfodApp will disconnect.
} else if('Z'==cmd) { // user pressed -- '*****'
// << add your action code here for this button
sendMainMenuUpdate(); // always send back a pfod msg otherwise pfodApp will disconnect.
} else if('C'==cmd) { // user pressed -- 'Insert coin'
// << add your action code here for this button
sendMainMenuUpdate(); // always send back a pfod msg otherwise pfodApp will disconnect.
} else {
// unknown command
Serial.print(F("{}")); // always send back a pfod msg otherwise pfodApp will disconnect.
}
}
}
}
void sendMainMenu() {
Serial.print(F("{.")); // start a Menu screen pfod message
send_menuContents(); // send the menu contents
Serial.print(F("}")); // close pfod message
}
void sendMainMenuUpdate() {
Serial.print(F("{:")); // start an Update Menu pfod message
send_menuContents(); // send the menu contents
Serial.print(F("}")); // close pfod message
}
// modify this method if you need to update the menu to reflect state changes
void send_menuContents() {
// send menu prompt
Serial.print(F("<l><+2><b>Arcade control"));
// send menu items
Serial.print(F("|P~<r><+1><b>Power is `"));
Serial.print(digitalRead(cmd_P_pin)); // read current output state 0 Low or 1 High
Serial.print(F("~~OFF\\ON")); // Note the \\ inside the "'s to send \
Serial.print(F("|L~<w><+1><b>Lights are `"));
Serial.print(digitalRead(cmd_L_pin)); // read current output state 0 Low or 1 High
Serial.print(F("~~OFF\\ON")); // Note the \\ inside the "'s to send \
Serial.print(F("|S~<l><+1><b>Sound is `"));
Serial.print(digitalRead(cmd_S_pin)); // read current output state 0 Low or 1 High
Serial.print(F("~~OFF\\ON")); // Note the \\ inside the "'s to send \
Serial.print(F("|Z~<y><+1><b>*****"));
Serial.print(F("|C~<a><+1><b>Insert coin"));
// ============ end of menu item ===========
}
//============================ you can remove from here on if you have the pfodParser library installed
// and use #include <pfodParser.h> at the top of this file
// this is the pfodParser.cpp file with comments, constants and un-used methods removed
pfodParser::pfodParser() {
init();
}
void pfodParser::init() {
argsCount = 0;
argsIdx = 0;
args[0] = 0;
args[1] = 0;
parserState = ((byte)0xff);
}
byte* pfodParser::getCmd() {
return args;
}
byte* pfodParser::getFirstArg() {
byte* idxPtr = args;
while( *idxPtr != 0) {
++idxPtr;
}
if (argsCount > 0) {
++idxPtr;
}
return idxPtr;
}
byte pfodParser::getArgsCount() {
return argsCount;
}
byte pfodParser::parse(byte in) {
if ((parserState == ((byte)0xff)) || (parserState == ((byte)'}'))) {
parserState = ((byte)0xff);
if (in == ((byte)'{')) {
init();
parserState = ((byte)'{');
}
return 0;
}
if ((argsIdx >= (255-2)) &&
(in != ((byte)'}'))) {
init();
return 0;
}
if (parserState == ((byte)'{')) {
parserState = ((byte)0);
}
if ((in == ((byte)'}')) || (in == ((byte)'|')) || (in == ((byte)'~')) || (in == ((byte)'`'))) {
args[argsIdx++] = 0;
if (parserState == ((byte)0xfe)) {
argsCount++;
}
if (in == ((byte)'}')) {
parserState = ((byte)'}'); // reset state
return args[0];
} else {
parserState = ((byte)0xfe);
}
return 0;
}
args[argsIdx++] = in;
return 0;
}
byte* pfodParser::parseLong(byte* idxPtr, long *result) {
long rtn = 0;
boolean neg = false;
while ( *idxPtr != 0) {
if (*idxPtr == '-') {
neg = true;
} else {
rtn = (rtn<<3) + (rtn<<1);
rtn = rtn + (*idxPtr-'0');
}
++idxPtr;
}
if (neg) {
rtn = -rtn;
}
*result = rtn;
return ++idxPtr;
}
// ============= end generated code =========
I am using Arduino Pro Mini 3.3V, HC-05 bluetooth module and Samsung Galaxy Note. I guess that very fist line of code is the place where problem is hidden, but I cannot fully understand what are all those characters for.
Bluetooth module is OK, since other examples from the Net are running fine.
Hope you can help me, since there is no similar problem described on your site.
Thanks in advance. Best regards from Serbia.