integer bigger than 32

Hi, I’m sending intger numbers from C# to my arduino. Each number is send as character character and in order for the arduino to know the exacy integer value i’m sendin my value in brakets such as <123> this way the arduino will tell that the integer value is 123. Know my problem is that i want to send an integer 65600 but

int will only hold a number which is smaller than 32768

i tried to change the variable int = inInt to long = inInt but i can not make it work. below is my code

int will only hold a number which is smaller than 32768

More correct is int: "Integers are your primary datatype for number storage, and store a 2 byte value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1). "

however a unsigned int will hold: "Unsigned ints (unsigned integers) are the same as ints in that they store a 2 byte value. Instead of storing negative numbers however they only store positive values, yielding a useful range of 0 to 65,535 (2^16) - 1). "

Likewise a long and a unsigned long will have different value ranges they can hold.

Your code didn’t post so I can’t comment on it.

Lefty

hi lefty, thanks for the info. this is my code, how shall i use the unisigned integer so that it will accept a value bigger than 32767

char inData[10];
int index;
boolean started = false;
boolean ended = false;
boolean final = false;
int serialValues[16];
int serialIndex = 0;
const int Pin13 = 13;
const int Pin12 = 12;
const int Pin11 = 11;
const int Pin10 = 10;
const int Pin7 = 7;
const int Pin6 = 6;
const int Pin5 = 5;
const int Pin4 = 4;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

//int lastButtonState = 0;

void setup()
{
//Serial1.begin(9600);
Serial.begin(9600);

//setting pinouts
pinMode(Pin13, INPUT);
pinMode(Pin12, INPUT);
pinMode(Pin11, INPUT);
pinMode(Pin10, INPUT);

pinMode(Pin7, OUTPUT);
pinMode(Pin6, OUTPUT);
pinMode(Pin5, OUTPUT);
pinMode(Pin4, OUTPUT);

}

void loop()
{
while(Serial.available() > 0)
{
char aChar = Serial.read();
if(aChar == ‘<’)
{
started = true;
index = 0;
inData[index] = ‘\0’;
}
else if(aChar == ‘>’)
{
ended = true;
}

else if(started)
{
inData[index] = aChar;
index++;
inData[index] = ‘\0’;
}

else if (aChar ==’*’)
{
final = true;
}
}

if(started && ended)
{
// Convert the string to an integer
int inInt = atoi(inData);
Serial.println(inInt);
// Use the value
serialValues [serialIndex] = inInt;
serialIndex++;

// Get ready for the next time
started = false;
ended = false;

index = 0;
inData[index] = ‘\0’;
}

if(final)
while(1)
{
// loop through the serialValues, and do something
for(int b=0; b <3;b++ )
{
buttonState1 = digitalRead(Pin13);
buttonState2 = digitalRead(Pin12);
buttonState3 = digitalRead(Pin11);
buttonState4 = digitalRead(Pin10);

int nextVal = serialValues**;**

** // I1 and any output**

** if (nextVal == 384 && buttonState1 == HIGH) **
** digitalWrite(Pin7, HIGH); //Q1 **
** else if (nextVal == 384 && buttonState1 == LOW) **
** digitalWrite(Pin7, LOW); //Q1**

** if (nextVal == 1152 && buttonState1 == HIGH) **
** digitalWrite(Pin6, HIGH); //Q2 **
** else if (nextVal == 1152 && buttonState1 == LOW) **
** digitalWrite(Pin6, LOW); //Q2**

** if (nextVal == 2176 && buttonState1 == HIGH)**
** digitalWrite(Pin5, HIGH); //Q3 **
** else if (nextVal == 2176 && buttonState1 == LOW)**
** digitalWrite(Pin5, LOW); //Q3 **

** if (nextVal == 4224 && buttonState1 == HIGH)**
** digitalWrite(Pin4, HIGH); //Q4 **
** else if (nextVal == 4224 && buttonState1 == LOW)**
** digitalWrite(Pin4, LOW); //Q4**

** if (nextVal == 8320 && buttonState1 == HIGH)**
** digitalWrite(Pin7, LOW); //Q1^**
** else if (nextVal == 8320 && buttonState1 == LOW)**
** digitalWrite(Pin7, HIGH); //Q1^ **

** if (nextVal == 16512 && buttonState1 == HIGH)**
** digitalWrite(Pin6, LOW); //Q2^**
** else if (nextVal == 16512 && buttonState1 == LOW)**
** digitalWrite(Pin6, HIGH); //Q2^ **

** if (nextVal == 32896 && buttonState1 == HIGH)**
** digitalWrite(Pin5, LOW); //Q3^**
** else if (nextVal == 32896 && buttonState1 == LOW)**
** digitalWrite(Pin5, HIGH); //Q3^ **

** if (nextVal == 65664 && buttonState1 == HIGH)**
** digitalWrite(Pin5, LOW); //Q4^**
** if (nextVal == 65664 && buttonState1 == LOW)**
** digitalWrite(Pin5, HIGH); //Q4^ **

** // I2 and any output**

** if (nextVal == 320 && buttonState2 == HIGH) **
** digitalWrite(Pin7, HIGH); //Q1 **
** else if (nextVal == 320 && buttonState2 == LOW) **
** digitalWrite(Pin7, LOW); //Q1**

** if (nextVal == 1088 && buttonState2 == HIGH) **
** digitalWrite(Pin6, HIGH); //Q2 **
** else if (nextVal == 1088 && buttonState2 == LOW) **
** digitalWrite(Pin6, LOW); //Q2**

** if (nextVal == 2112 && buttonState2 == HIGH)**
** digitalWrite(Pin5, HIGH); //Q3 **
** else if (nextVal == 2112 && buttonState2 == LOW)**
** digitalWrite(Pin5, LOW); //Q3 **

** if (nextVal == 4160 && buttonState2 == HIGH)**
** digitalWrite(Pin4, HIGH); //Q4 **
** else if (nextVal == 4160 && buttonState2 == LOW)**
** digitalWrite(Pin4, LOW); //Q4**

** if (nextVal == 8256 && buttonState2 == HIGH)**
** digitalWrite(Pin7, LOW); //Q1^**
** else if (nextVal == 8256 && buttonState2 == LOW)**
** digitalWrite(Pin7, HIGH); //Q1^ **

** if (nextVal == 16448 && buttonState2 == HIGH)**
** digitalWrite(Pin6, LOW); //Q2^**
** else if (nextVal == 16448 && buttonState2 == LOW)**
** digitalWrite(Pin6, HIGH); //Q2^ **

** if (nextVal == 32832 && buttonState2 == HIGH)**
** digitalWrite(Pin5, LOW); //Q3^**
** else if (nextVal == 32832 && buttonState2 == LOW)**
** digitalWrite(Pin5, HIGH); //Q3^ **

** if (nextVal == 65600 && buttonState2 == HIGH)**
** digitalWrite(Pin5, LOW); //Q4^**
** if (nextVal == 65600 && buttonState2 == LOW)**
** digitalWrite(Pin5, HIGH); //Q4^**

** // I3 and any output**

** if (nextVal == 288 && buttonState3 == HIGH) **
** digitalWrite(Pin7, HIGH); //Q1 **
** else if (nextVal == 288 && buttonState3 == LOW) **
** digitalWrite(Pin7, LOW); //Q1**

** if (nextVal == 1056 && buttonState3 == HIGH) **
** digitalWrite(Pin6, HIGH); //Q2 **
** else if (nextVal == 1056 && buttonState3 == LOW) **
** digitalWrite(Pin6, LOW); //Q2**

** if (nextVal == 2080 && buttonState3 == HIGH)**
** digitalWrite(Pin5, HIGH); //Q3 **
** else if (nextVal == 2080 && buttonState3 == LOW)**
** digitalWrite(Pin5, LOW); //Q3 **

** if (nextVal == 4128 && buttonState3 == HIGH)**
** digitalWrite(Pin4, HIGH); //Q4 **
** else if (nextVal == 4128 && buttonState3 == LOW)**
** digitalWrite(Pin4, LOW); //Q4**

** if (nextVal == 8224 && buttonState3 == HIGH)**
** digitalWrite(Pin7, LOW); //Q1^**
** else if (nextVal == 8224 && buttonState3 == LOW)**
** digitalWrite(Pin7, HIGH); //Q1^ **

** if (nextVal == 16416 && buttonState3 == HIGH)**
** digitalWrite(Pin6, LOW); //Q2^**
** else if (nextVal == 16416 && buttonState3 == LOW)**
** digitalWrite(Pin6, HIGH); //Q2^ **

** if (nextVal == 32800 && buttonState3 == HIGH)**
** digitalWrite(Pin5, LOW); //Q3^**
** else if (nextVal == 32800 && buttonState3 == LOW)**
** digitalWrite(Pin5, HIGH); //Q3^ **

** if (nextVal == 65568 && buttonState3 == HIGH)**
** digitalWrite(Pin5, LOW); //Q4^**

I see you are using values up to “Know my problem is that i want to send an integer 65600” . This will not fit into even a unsigned int (see my prior post of data type ranges) and would have to use long variables. As to how to change you program, that is something I’m not up to, however it should just be a manner of using long variables and arrays everywhere you handle the received value.

PS: I suggest when you need to post code that you select it and then press the # button (insert code) at the top of the edit window. That will place the code into a formatted window that is easier to read and scroll. Thanks
Lefty

thanks lefty :slight_smile: