Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / trouble about void loop in Arduino on: January 30, 2013, 09:31:20 am
Hi,
I have programmed an Arduino Leonardo with the following code:

Code:
#include <stdio.h>
#include <Wire.h>

#define RLY08_ADDRESS1 0x38

int i;
char command[3];


void loop() {
  if (Serial1.available() > 0) {
    
    for (i=0; i<2; i++){
      command[i] = Serial1.read();
    }
    command[2] = '\0';
  }
  delay(100);
  
  
    if (strcmp(command, "11") == 0){
      Wire.beginTransmission(0x38);
      Wire.write(0x00);
      Wire.write(0x65);
      Wire.endTransmission();
      delay(500);
      Wire.beginTransmission(0x38);
      Wire.write(0x00);
      Wire.write(0x6F);
      Wire.endTransmission();
    }
    
      
  }

The question is:
I receive, through serial communication, 2 bytes and if the bytes are "11" in unsigned char format the if condition (strcmp(command, "11") == 0)is executed and it works fine but the execution of the instruction is one time only.
If I receive any bytes from serial communication, the  if instruction (strcmp(command, "11") == 0) is not executed more. Why? the char command[2] contain the "11" values always.


Regards,


Moderator edit: Italic tags swapped for CODE TAGS
Pages: [1]