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);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.