i want to compare the data from "receivedDataFromPC" but cannot get any results from the if statement from inside the void loop. but when comparing the data from "integerFromPC" it gets a result. one more thing when entering more than 4 or five data for the integerFromPC it gets negative, why is that? im planning on using this for my mini-project for controlling an led strip wirelessly through bluetooth. thanks!
i want to compare the data from "receivedDataFromPC" but cannot get any results from the if statement from inside the void loop
messageFromPC is a string so you cannot use == to compare for equality. Use the strcmp() function. And you must compare string to string, not string to integer like in:
if(messageFromPC == 1) // his will not work
but when comparing the data from "integerFromPC" it gets a result. one more thing when entering more than 4 or five data for the integerFromPC it gets negative, why is that?
integerFromPC is an int data type. The int data type holds numbers from -32768 to 32767. Numbers outside that range will overflow. See Arduino data types to see the ranges for different data types.
groundFungus:
messageFromPC is a string so you cannot use == to compare for equality. Use the strcmp() function. And you must compare string to string, not string to integer like in:
If i'm correct, doing that(strcmp) will require to store all the supposedly compared string into a variable. Is there a simple way of doing this when comparing more than 2 string?
i realized i could just use switch case in void loop since i read that i could use a string without setting up all the compared data inside a variable, but it gave me an error of "switch quantity not an integer". so i think im back at using strcmp
thanks! it works the way that im expecting, does putting the 0 at end of it makes it so that switch case will only read a single 'char' character? can you please tell me how it works?
An array is a group of items of the same data type. Each item (element) has a number (starting at 0) denoting its position in the array. The number is called the array index. The notation for picking a particular item from the array is the index enclosed in square brackets. The expression: array[0] refers to the first element of the array.
A string (note small 's') is a special kind of array. A string is a null terminated character array which means that the array ends with a '\0'. An array of characters that does not end with a '\0' is just an array, not a string.
An array is a group of items of the same data type. Each item (element) has a number (starting at 0) denoting its position in the array. The number is called the array index. The notation for picking a particular item from the array is the index enclosed in square brackets. The expression: array[0] refers to the first element of the array.
A string (note small 's') is a special kind of array. A string is a null terminated character array which means that the array ends with a '\0'. An array of characters that does not end with a '\0' is just an array, not a string.