exit status 1
Compilation error: invalid conversion from 'const char*' to 'unsigned int' [-fpermissive]
uint16_t color;
color=(str.remove("C")).toInt());
exit status 1
Compilation error: invalid conversion from 'const char*' to 'unsigned int' [-fpermissive]
uint16_t color;
color=(str.remove("C")).toInt());
Please post a full sketch showing the data type of the str variable
Is it a String or a string, for example ?
What do you see if you split the single statement and print the result of individual functions ?
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial
#include <TFT_eSPI.h> // Hardware-specific library for ESP8266
// Invoke TFT library
TFT_eSPI tft = TFT_eSPI();
#include "BluetoothSerial.h"
//#define USE_PIN // Uncomment this to use PIN during pairing. The pin is specified on the line below
const char *pin = "1234"; // Change this to more secure PIN.
String device_name = "RemoteControlX";
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
SerialBT.begin(device_name); //Bluetooth device name
Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str());
//Serial.printf("The device with name \"%s\" and MAC address %s is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str(), SerialBT.getMacString()); // Use this after the MAC method is implemented
#ifdef USE_PIN
SerialBT.setPin(pin);
Serial.println("Using PIN");
#endif
tft.begin();
tft.setRotation(2); // 0 & 2 Portrait. 1 & 3 landscape
tft.fillScreen(TFT_BLACK);
tft.textcolor=TFT_WHITE;
}
uint16_t color;
uint16_t xval;
uint16_t yval;
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
String str = SerialBT.readString();
if(str.startsWith("C"))
{
color=(str.remove("C")).toInt());
else
if(str.startsWith("X"))
{
xval=(str.remove("X")).toInt();
else
if(str.startsWith("Y"))
{
yval=(str.remove("Y")).toInt();
else
if(str.startsWith("P"))
{
tft.drawPixel(xval,yval,color)
else
tft.print(str);
}
}
}
}
}
delay(20);
}
do not look to that description on the top, I edited the bt serial example to TFT
It looks like you may have misunderstood what the remove() function does
String greeting = "hello";
greeting.remove(2, 2); // greeting now contains "heo"
That’s the doc for the remove() function
It does not accept a character string literal (const char *
) as a parameter
Maybe you wanted to use replace()
?
...or, as here, a string
Indeed i should have written a const char *
/ string literal
color=(str.replace("C","")).toInt());
im getting invalid use of void ???
I guess you did not read the doc fully… the function does not return anything.
Returns
Nothing
So you first remove the string, then you call toInt() on the now cleaned up string to get the int
(Please learn to use code tags when pasting code)
str.replace("C","")); // get rid of C
color = str.toInt(); // transform into a long (signed)
What does the String look like? If C is alsays in front as first character you could also just skip it and use other functions to get the conversion going
string is coming from BTSERIAL. But theres a if(working with no error) that checks if it starts with
Plannned like C65535
I think after 50 plus topics and 300 plus posts, it's not unreasonable to expect you to post actual code and actual error messages.
Who knows? You may actually learn something.
consider
const char *inp = "C65535";
void setup (void)
{
Serial.begin (9600);
char c;
unsigned val;
sscanf (inp, "%c%d", &c, &val);
Serial.println (val);
}
void loop (void)
{
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.