Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I need to delete some characters from string. When i used erase it doesn`t work, compilation error erase no member named. Please help me. Probaly it is because I writing for Arduino UNO.
Arduino String class is quite different from std::string. For example erase doesn't exists. But there is method remove.
Anyway, you should start with: https://www.arduino.cc/en/Reference/HomePage
Expanding on what KIIV suggested, you could possibly do something like this:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
String words = "This is a sentence."; //reassign same string at the start of loop.
delay(1000);
Serial.println(words);
char c;
char no = ' '; //character I want removed.
for (int i=0; i<words.length()-1;++i){
c = words.charAt(i);
if(c==no){
words.remove(i, 1);
}
}
Serial.println(words);
delay(5000);//5 second delay, for demo purposes.
}
The Libraries in Arduino are customized in order to factor the memory constraints of the target Micro controller. For example , the Uno runs on a mega328P Atmel (now Microchip) device, which has only has 32 KB flash memory.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have written a simple FORTH-like interpreter where I get input a line at a time and process it like this:
std::string line;
while (!std::cin.eof()) {
std::getline(std::cin, line);
std::istringstream input(line);
std::copy(std::istream_iterator<std::string>(input),
std::istream_iterator<std::string>(),
std::back_inserter(data.input_));
// some work
}
And if I input 5 5 + . <enter> it displays like this:
5 5 + .
10 ok
But what I would like it show is:
5 5 + . 10 ok
In other words a newline should be accepted to mean end of line input but it should not be echoed to std::cout.
Having done some reading it seems I will not be able to achieve this in std c++ (is this true?) but I can use the functions in the termios library to set up the console this way on a POSIX system without messing with other console functions such as ctl-c handling etc. I haven't figured out exactly how though. Can anyone show me the way?
You can Use VT100 Escape Sequences for customising console output (VT100 ESC SEQUENCES). in this case;
use \033[1A for go 1 line up, \033[nC (n is int value) to Go n letter right
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have some knowledge about C++, but I stumbled upon an problem. I want the user to enter some text, but when it takes longer than X seconds, the program will go on. I guess, it is not possible, but maybe you know something about it.
It will be in the command line, without GUI.
I am not certain how the programm will look like, but it will be something like a CMD-RPG. I wanted to use Quick Time Events to make it a little bit more exciting.
I cant comment so I will just leave this here
Input with a timeout in C++
Since I cannot comment, I will simply leave this as an answer.
One possible way to solve this problem is to have 2 threads:
Input capture thread: since receiving input is a thread-blocking action, you should have a thread that simply polls for user input, placing that input into a thread-safe buffer
Quick-time function on main thread: a function that will be responsible for executing the quick-time event. Something like the following could be done (pseudo code):
clear input buffer //the buffer provided by the input capture thread
bool success = false;
while(current time < ending time)
{
if(input buffer isn't empty)
{
get contents of input buffer and send contents to cout
if (user has finished input correctly)
{
success = true;
break;
}
clear buffer
}
}
return success;
For this to work, you would need to turn off echo on the command prompt (see this page for more info)
Although Diogo's reference is excellent (and informative), I believe this answer is more applicable than since the OP has indicated that this program will be ran on Windows.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Emmm...I am writing a code that it can read the user input immediately after user press the key...
and I found the code online:
initscr();
cbreak();
noecho();
scrollok(stdscr, TRUE);
nodelay(stdscr, TRUE);
while (true) {
if (getch() == 'g') {
printw("You pressed G\n");
}
napms(500);
printw("Running\n");
}
and it worked pretty well..then I turn to use cout to print what I read in getch()...
I am now confused how nucurse.h handle the cout or I mean standard I/O..?
initscr tells (n)curses to write to the standard output. However, ncurses buffers its writes separately from the cout stream (see for example Output buffering in the ncurses6 release notes), and flushes its output when told to refresh. getch does a refresh call as a side-effect. There aren't other refresh calls in your example.
ncurses (like SVr4 curses) sets its input to raw mode, but that aspect is not related to your problem with cout.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I'm trying to find a way for my Arduino to recognize some of the commands I'm attempting to send over serial (via Raspberry Pi)
I'm come as far as to detect 2 commands, but I'm stuck at my last.
To give a little bit more detail, I have my fingerprint scanner (GT-511C3) connected, and the library installed that will make it work.
That said, with the first 2 commands consist the verifying of fingerprints to ID (which works great) and the enrolling of fingerprints to new ID's (also work great) these parts of the script are triggered by the respective ASCII code "0" and "1".
My last, and problematic command "2" to remove an ID, is where I'm seeking help with.
Here's the code I'm currently working with:
if(ser == '2'){
while(val2 == 0){
char val3 = 0;
delay(10);
Serial.println("Type the ID to be deleted");
delay(2500);
fps.DeleteID(Serial.read());
val3 == Serial.read();
delay(10);
Serial.println("Deleted ID:");
Serial.print(val3);
delay(10);
val2 = 1;
}
}
I'm attempting to send the ASCII code "2" over Raspberry Pi through serial to the Arduino, followed by the ID that needs to be removed. It triggers after the command "2" is send, but refuses to read the ID and as such, I'm unable to finish it.
Any help or insight would really be appreciated.
val3 == Serial.read(); should be val3 = Serial.read();. You have an extra = which turns it into a useless comparison.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a problem with programming movement using C++ and Ncurses.
I'm programming a pacman and the main problem is, that I just want last pressed key in time period.
When I use usleep, it saves every key pressed during sleeping and then it's working with that in the order.
Thanks for ideas.
What did you try?
Something like this should work, if I understood correctly what you try to achieve:
int t = your_delay;
while (t --> 0)
{
sleep(1);
c = getch();
}
If you really need to time it down to the microsecond, this might not be the best approach, but if you can have some tolerance, this should be enough.
Are you in no-delay mode? If so, this might work:
usleep(your_delay);
last_key = ERR;
while ( (key=getch()) != ERR ) {
last_key = key;
}
// "last_key" now holds most recent key, if there was one, else ERR