Skip to main content
formatted code
Source Link
chrisl
  • 16.6k
  • 2
  • 18
  • 27

const int Button_1 = 2; unsigned int s =0; void setup () {
Serial.begin(115200) ; pinMode(Button_1,INPUT); } void loop() { if (digitalRead(Button_1)) { s = 61805; Serial.write(highByte(s)) ; Serial.write(lowByte(s)); delay (5); s=0; } else { s = 60005; Serial.write(highByte(s)) ; Serial.write(lowByte(s)); delay (5); s=0; } }

const int Button_1 = 2;
unsigned int s =0;
void setup () 
{   
   Serial.begin(115200) ;
   pinMode(Button_1,INPUT);
} 
void loop() 
{
  if (digitalRead(Button_1))
  {
     s = 61805;
     Serial.write(highByte(s)) ;
     Serial.write(lowByte(s));
     delay (5);
     s=0;
  } 
  else
  {
     s = 60005;
     Serial.write(highByte(s)) ;
     Serial.write(lowByte(s));
     delay (5);
     s=0;
  } 
} 

(code for slave)

unsigned int upperByte, lowerByte, r=0,p=0; void setup() { Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT) ; } void loop () { If (Serial.available()>1) { upperByte = Serial.read(); lowerByte = Serial.read(); } r = (upperByte << 8) + lowerByte ;

while (r==61805) { digitalWrite(LED_BUILTIN, HIGH) ; } while (r==60005) { digitalWrite(LED_BUILTIN, LOW) ; } }

unsigned int upperByte, lowerByte, r=0,p=0;
void setup() 
{
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT) ;
} 
void loop () 
{
  If (Serial.available()>1)
  {
     upperByte = Serial.read();
     lowerByte = Serial.read();
  }
    r = (upperByte << 8) + lowerByte ;
 
   while (r==61805)
    {
        digitalWrite(LED_BUILTIN, HIGH) ;
    } 
    while (r==60005)
    {
        digitalWrite(LED_BUILTIN, LOW) ;
    } 
} 

const int Button_1 = 2; unsigned int s =0; void setup () {
Serial.begin(115200) ; pinMode(Button_1,INPUT); } void loop() { if (digitalRead(Button_1)) { s = 61805; Serial.write(highByte(s)) ; Serial.write(lowByte(s)); delay (5); s=0; } else { s = 60005; Serial.write(highByte(s)) ; Serial.write(lowByte(s)); delay (5); s=0; } }

(code for slave)

unsigned int upperByte, lowerByte, r=0,p=0; void setup() { Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT) ; } void loop () { If (Serial.available()>1) { upperByte = Serial.read(); lowerByte = Serial.read(); } r = (upperByte << 8) + lowerByte ;

while (r==61805) { digitalWrite(LED_BUILTIN, HIGH) ; } while (r==60005) { digitalWrite(LED_BUILTIN, LOW) ; } }

const int Button_1 = 2;
unsigned int s =0;
void setup () 
{   
   Serial.begin(115200) ;
   pinMode(Button_1,INPUT);
} 
void loop() 
{
  if (digitalRead(Button_1))
  {
     s = 61805;
     Serial.write(highByte(s)) ;
     Serial.write(lowByte(s));
     delay (5);
     s=0;
  } 
  else
  {
     s = 60005;
     Serial.write(highByte(s)) ;
     Serial.write(lowByte(s));
     delay (5);
     s=0;
  } 
} 

(code for slave)

unsigned int upperByte, lowerByte, r=0,p=0;
void setup() 
{
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT) ;
} 
void loop () 
{
  If (Serial.available()>1)
  {
     upperByte = Serial.read();
     lowerByte = Serial.read();
  }
    r = (upperByte << 8) + lowerByte ;
 
   while (r==61805)
    {
        digitalWrite(LED_BUILTIN, HIGH) ;
    } 
    while (r==60005)
    {
        digitalWrite(LED_BUILTIN, LOW) ;
    } 
} 
added 946 characters in body
Source Link
Mayank
  • 23
  • 1
  • 5

I'm trying to send some big numbers ranging from 0-62000 from one arduino to another via serial communication. I'm using unsigned int to hold values from 0 to 65535. And I'm using serial.print() and serial.write () to send numbers and serial.read()-'0' ; to receive numbers, but I'm unable to send and receive numbers above 9. Please help me.

Here is my code -

(For master)

const int Button_1 = 2; unsigned int s =0; void setup () {
Serial.begin(115200) ; pinMode(Button_1,INPUT); } void loop() { if (digitalRead(Button_1)) { s = 61805; Serial.write(highByte(s)) ; Serial.write(lowByte(s)); delay (5); s=0; } else { s = 60005; Serial.write(highByte(s)) ; Serial.write(lowByte(s)); delay (5); s=0; } }

(code for slave)

unsigned int upperByte, lowerByte, r=0,p=0; void setup() { Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT) ; } void loop () { If (Serial.available()>1) { upperByte = Serial.read(); lowerByte = Serial.read(); } r = (upperByte << 8) + lowerByte ;

while (r==61805) { digitalWrite(LED_BUILTIN, HIGH) ; } while (r==60005) { digitalWrite(LED_BUILTIN, LOW) ; } }

I'm trying to send some big numbers ranging from 0-62000 from one arduino to another via serial communication. I'm using unsigned int to hold values from 0 to 65535. And I'm using serial.print() and serial.write () to send numbers and serial.read()-'0' ; to receive numbers, but I'm unable to send and receive numbers above 9. Please help me.

I'm trying to send some big numbers ranging from 0-62000 from one arduino to another via serial communication. I'm using unsigned int to hold values from 0 to 65535. And I'm using serial.print() and serial.write () to send numbers and serial.read()-'0' ; to receive numbers, but I'm unable to send and receive numbers above 9. Please help me.

Here is my code -

(For master)

const int Button_1 = 2; unsigned int s =0; void setup () {
Serial.begin(115200) ; pinMode(Button_1,INPUT); } void loop() { if (digitalRead(Button_1)) { s = 61805; Serial.write(highByte(s)) ; Serial.write(lowByte(s)); delay (5); s=0; } else { s = 60005; Serial.write(highByte(s)) ; Serial.write(lowByte(s)); delay (5); s=0; } }

(code for slave)

unsigned int upperByte, lowerByte, r=0,p=0; void setup() { Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT) ; } void loop () { If (Serial.available()>1) { upperByte = Serial.read(); lowerByte = Serial.read(); } r = (upperByte << 8) + lowerByte ;

while (r==61805) { digitalWrite(LED_BUILTIN, HIGH) ; } while (r==60005) { digitalWrite(LED_BUILTIN, LOW) ; } }

changed title to reflect the actual question
Source Link
Duncan C
  • 5.8k
  • 3
  • 19
  • 31

I'm trying to send some big numbers ranging from 0-62000 from one arduino to another via serial communication. I'm using unsigned int to hold values from 0 to 65535.. And I'm using serial.print() and serial.write () to send numbers and serial.read()-'0' ; to receive numbers, but I'm unable to send and receive numbers above 9. Please help me.

I'm trying to send some big numbers ranging from 0-62000 from one arduino to another via serial communication. I'm using unsigned int to hold values from 0 to 65535.. And I'm using serial.print() and serial.write () to send numbers and serial.read()-'0' ; to receive numbers, but I'm unable to send and receive numbers above 9. Please help me.

I'm trying to send some big numbers ranging from 0-62000 from one arduino to another via serial communication. I'm using unsigned int to hold values from 0 to 65535. And I'm using serial.print() and serial.write () to send numbers and serial.read()-'0' ; to receive numbers, but I'm unable to send and receive numbers above 9. Please help me.

Loading
Source Link
Mayank
  • 23
  • 1
  • 5
Loading