problem with the program.

Hey, so, I wrote code in Arduino its goal is to keep characters that it receives and store them in the array, and print the array on the LCD, if there is a sequence of letters "OPF".

The character i send are from VISUAL STUDIO ( I made a button that when its pressed it sends a the first letter of the sequence and when I press the other two buttons it sends the next 2 letters in the sequence so it will make "OPF".)

The arduino does receives the signals from the VISUAL STUDIO, but for some reason the program does not print the array, can anyone help me please?

Notes: The LCD works.

#include <LiquidCrystal.h>
char arr[3];
int c2 = 0;
char data = Serial.read();
int i;
LiquidCrystal lcd (53,51,49,47,45,43);

void setup()
{
lcd.begin (16,2);
Serial.begin(9600);
}

void loop(){
while(Serial.available() > 0){

if (data == 'O' && c2 == 0)
c2 = 1;

else if (data == 'P' && c2 == 1)
c2 ++;

else if (data == 'F' && c2 == 2)
c2 ++;

if (c2 == 3){
for (i=0; i<9; i++)
arr = data;

  • c2 = 0;*
  • lcd.print (arr);*
  • }*
  • }*
    }
Void loop () {
C2 int = 0;
For (i = 0; i <9; i ++)

That didn't actually compile, did it?

Please post actual code.
This time, use code tags please.

AWOL:

Void loop () {
C2 int = 0;
For (i = 0; i <9; i ++)

That didn't actually compile, did it?

Please post actual code.
This time, use code tags please.

Hi, for some reason, in the translation the code got lost, i UPDATED the real code ! please have a look :slight_smile:

And the code tags? (I assume the code didn't have italics)

for some reason, in the translation the code got lost

What translation?

AWOL:
And the code tags? (I assume the code didn't have italics) What translation?

Nvm the translation. The code is there as i wrote it :slight_smile:

And what are the code tags? what does it mean?

(deleted)

spycatcher2k:
char data = Serial.read(); Are you sure you want that here?

if (data == 'O' && c2 == 0)
c2 = 1;

You never change data anywhere, so why test it?

What Exactly do you mean?

You initialise data, but never update it while your sketch is running.

Benoson:
And what are the code tags? what does it mean?

You mean you just started posting without first reading the How to Use this Forum thread? Learning to read first and write second is an important lesson if you ever hope to be a programmer.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Tom.. :slight_smile:

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Tom.. :slight_smile:

Hi :smiley: thanks for the help, but im in a hurry and my English is not that well, it will be hard for me to read and understand anything, most of what i post is from google translate. i just want someone to help me with this code (its due to 2 days from now).

If you're in a hurry, then its all the more important you read the instructions for posting, that will
save unnecessary to-and-fro of questions and answers.

tl;dr
You're missing a Serial.read after the Serial.available

AWOL:
tl;dr
You're missing a Serial.read after the Serial.available

the Serial.read is the 'data'

That's right, you have to read it, just after you've checked there's something there to read, not once, before you've even told the serial port what speed to run at.