Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am using an Arduino Mega2560, and want to \'receive\' and \'send\' a \'long\'

ID: 3820904 • Letter: I

Question

I am using an Arduino Mega2560, and want to 'receive' and 'send' a 'long' up to 70000 using 17 bits, 3 frames together to another Arduino with a 50ms gap between each packet. At the moment I only know how to write a function to receive and send char. (see below). How do I write a function to break the number down in to frames for sending, and convert back when receiving?

unsigned char ReceivedByte;

void setup(void) {
UCSR1A = B00000000;
UCSR1B = B00011000;
UCSR1C = B00000110;
UBRR1 = 103; //9600 baud

}

unsigned char RX(void)

{
while ((UCSR1A & (1 << RXC1)) == 0) {};   
return(UDR1);
}

void TX(unsigned char TXData)

{

while ((UCSR1A & (1 << UDRE1)) == 0) {};
UDR1 = TXData;
}

void loop(void) {
ReceivedByte= RX();
TX(ReceivedByte);   
}

Explanation / Answer

void setup() {
initialize the digital pin as an output:

Serial.begin(9600);
Serial.println("Read: ");
}


void loop() {   

char x= "example";
int resultat = (strlen(x));
Serial.println(resultat);
delay(1000);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote