Help needed ( which i not expected) ( Basic coding)

Hello.

Actually i basically try to learn basics about the using of ardunio and loop problems guys. And what i'm trying to do is using LED's to command them with some basic notations like " cw" Clockwise or "cc" Counter clockwise. and my codes shown below. I have done that project by using " '1' , '2' and '0' " instead of " cw , cc " i needed to use Arrays to do , arrays or the strings may be problematic but i don't have such knowledge to where the mistake i've done.

int x = 200;
int a =0 ;
int i =0 ;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(12 ,LOW);
digitalWrite(11, LOW);
digitalWrite(13, LOW);

}

void loop()
{ int Array[4] = {0,0,1,2};
String stringOne = "cw";
String stringTwo = "cc";
String stringThree = "st";
if(Serial.available() > 0)
{
for(i < 4) {
Array = Serial.read() ;

  • } *

_ if(Array == 'stringOne' ) {_
* a = 1 ;}*
_ if(Array == 'stringTwo' ) {
* a = 2 ;}
if(Array == 'stringThree' ) {
a = 0 ;}
}
if(a==0) { loop3(); }
if(a==1) { loop1(); }
if(a==2) { loop2(); }
}*_

* void loop1() { *

* digitalWrite(13, HIGH);*
* delay(x);*
* digitalWrite(13,LOW);*
* delay(x);*
* digitalWrite(12, HIGH);*
* delay(x);*
* digitalWrite(12, LOW);*
* delay(x);*
* digitalWrite(11,HIGH);*
* delay(x);*
* digitalWrite(11, LOW);*
* delay(x);*

* }*

* void loop2() { *
* digitalWrite(11, HIGH);*
* delay(x);*
* digitalWrite(11,LOW);*
* delay(x);*
* digitalWrite(12, HIGH);*
* delay(x);*
* digitalWrite(12, LOW);*
* delay(x);*
* digitalWrite(13,HIGH);*
* delay(x);*
* digitalWrite(13, LOW);*
* delay(x); }*

* void loop3() { *
* digitalWrite(13, LOW);*
* digitalWrite(12, LOW);*
* digitalWrite(11, LOW); *
* }[/quote]*

i could not find the mistakes which i've done.
Error message just like this;
Arduino: 1.6.1 (Windows 8.1), Board: "Arduino Uno"
sketch_apr13a.ino: In function 'void loop()':
sketch_apr13a.ino:24:14: error: expected ';' before ')' token
sketch_apr13a.ino:28:5: error: expected primary-expression before 'if'
sketch_apr13a.ino:28:5: error: expected ';' before 'if'
sketch_apr13a.ino:28:5: error: expected primary-expression before 'if'
sketch_apr13a.ino:28:5: error: expected ')' before 'if'
Error compiling.
Any help appriciated...
thank you

   for(i < 4) {

The Arduino is programmed in C++, which is a superset of C. This is NOT what a for loop looks like. Go to the Reference page and look at the basic statements.

    if(Array == 'stringOne' ) {

After reading 4 integers and storing them in an array, how can you expect the array address to equal the ONE character you put in the single quotes? Which ONE key on your keyboard did you press to get that weird looking SINGLE character?

Ditch the lame String class NOW. Do NOT bypass learning about arrays and strings (NULL terminated arrays of chars) and proper text handling. If you do, you'll be forever crippled.

Let's get some basic stuff out of the way first.

void loop()
{ int Array[4] = {0, 0, 1, 2};

Each time through loop() the array will be set back to its fixed values. Is that what you want ?

 if (Serial.available() > 0)
  {
    for (i < 4) {
      Array = Serial.read() ;
    }

It looks like you are trying to put 4 values received into the array. How do you know that 4 values are available ? Have you seen other examples of a for loop that look like that and if so, where ? Assuming that there were no other problems how would the program know which element of the array to use to store each incoming byte ?

   if (Array == 'stringOne' ) {

How will the 4 characters read in ever equal the 9 characters ? ' is used to indicate that the value is a single character not a series of them.

Read up on arrays, for loops in C and C style strings (arrays of chars, not Strings, which are different things)

To do what you are trying to you need to read characters one at a time, put them in a suitably sized array of chars until the end of the input is reached then do the comparison.

Have a look at Serial input basics to get some ideas.

Thank you all.

i should read on the basics, im pretty new in C. (about 1 week).

Thanks for your comments and suggestions.

Have you looked at the examples in the IDE ? Do you have any experience with other programming languages ?

No experience, this is my first. Then i should carry on reading the examples.

The examples will help you up to a point but with no previous programming experience you may struggle with concepts such as for loops and arrays but there is plenty of C and C++ help online.

Don't be afraid to experiment with the examples. Take the Blink example and change the value used by the delay() function. Can you make it blink faster and slower ? Use the Arduino reference pages to help understand the Arduino specific functions such as pinMode(), digitalWrite(), digitalRead(), analogRead() etc

Look at the examples of input and output. Look at and understand the BlinkWithoutDelay and StateChangeDetection examples. Both techniques will be very useful in the near future.