Hi All,
A newbie question and a really stupid one indeed:$
I want to store some incoming data into an array and then compare it with an array that I have defined. I am posting the program here but it is Arduino based and uses the Wire library. But I don't want you to look into that, just have a look at the receive event handler, whatever I receive there, I want to store it in an array. And then compare it with G1 or G28. I am pretty sure the code is not complete in anyway and there is a lot missing and a lot wrong as well. I am still trying to learn arrays and I would really appreciate if someone could help me out as well as explain a bit, if that is not too much to ask.
#include <Wire.h>
//i2c address of the gen 6
int REP_RAP_ADDR = 4;
//my address
int CP_ADDR = 5;
int ledPin = 2;
void receiveEvent(int howMany)
{
while(0 < Wire.available()) // loop through all
{
char inData[512];
byte index = 0;
char javaid = Wire.receive();
Serial.print(javaid);
if(index < 512)
{
inData[index++] = javaid;
inData[index] = '\0';
}
}
}
void setup()
{
Wire.begin(CP_ADDR);
Wire.onReceive(receiveEvent); // register event so that anything received on i2c is sent to the serial
pinMode(ledPin, OUTPUT);
}
void loop()
{
char str1[] = "G1";
char str2[] = "G28";
if (strcmp(str1, "G1") == 0){
//turn dispenser on
digitalWrite(2, HIGH); }
if (strcmp(str2, "G28") == 0) {
//turn dispenser off
digitalWrite(2, LOW);}
}
Thank you in advance.