#include <OneButton.h>
#include <SerialTransfer.h>
const unsigned int MAX_MESSAGE_LENGTH = 12;
String command;
String value;
#define BUTTON_PIN1 2
OneButton btn1 = OneButton(
BUTTON_PIN1, // Input pin for the button
true, // Button is active LOW
true // Enable internal pull-up resistor
);
void setup() {
Serial.begin(9600);
Serial.println("Hello");
btn1.attachClick(writeCommand);
}
void writeCommand(){
Serial.write("POT:548");
delay(500);
}
void loop() {
btn1.tick();
while (Serial.available() > 0)
{
//Create a place to hold the incoming message
static char message[MAX_MESSAGE_LENGTH];
static unsigned int message_pos = 0;
//Read the next available byte in the serial receive buffer
char inByte = Serial.read();
//Message coming in (check not terminating character) and guard for over message size
if ( inByte != '\n' && (message_pos - MAX_MESSAGE_LENGTH - 1) )
{
//Add the incoming byte to our message
message[message_pos] = inByte;
message_pos++;
}
//Full message received...
else
{
String str = String(message);
int index = str.indexOf(':');
command = str.substring(0,index);
value = str.substring(command.length() + 1, str.length());
Serial.println(command);
//int n1 = str.toInt();
Serial.println(value);
if(command == "POT"){
//Serial.println("Potmeter command");
}
//Serial.println(sub_S);
//Add null character to string
message[message_pos] = '\0';
//Reset for the next message
message_pos = 0;
command = "";
str = "";
}
}
}