// Transmitter code (Arduino UNO to Arduino UNO communication)
// this version includes the use of potentiometer to set the transmission bitrate (bps) in the setup funtion (to change the bitrate, reset the MCU )
// The bitrate is selected by adjusting the potentiometer and pressing the pushbutton to exit WHILE loop
// In the LOOP function the pushbutton is used to restart transmission (resend message)
// The receiver part can be updated with pushbutton, that resets receiver (ground the reset pin) to wait for new incoming message
#include <LiquidCrystal.h>
#include <Manchester.h>
// Pin assignments
#define buttonPin 2
#define LCD_D4 4
#define LCD_D5 5
#define LCD_D6 6
#define LCD_D7 7
#define LCD_RS 8
#define LCD_EN 9
#define TX_PIN 3
// Transmit rate in bps
long TX_RATE;
// Initialize the LCD screen
bool buttonPressed = false; // Flag to indicate button press
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
uint8_t moo = 1; //last led status
uint8_t message[]= "Hello, world!";
void setup() {
pinMode(TX_PIN, OUTPUT);
digitalWrite(TX_PIN, moo);
man.setupTransmit(TX_PIN, MAN_300);
}
void loop() {
if (digitalRead(buttonPin) == LOW) { // Check if the button is pressed
delay(300); // Debounce delay
send_message();
}
}
uint8_t datalength=2; //at least two data
void send_message() {
for (int byte_idx = 0; byte_idx < strlen(message); byte_idx++) {
char tx_byte = message[byte_idx];
// Clear the second line of the display
lcd.noCursor();
lcd.setCursor(0, 1);
lcd.print(" "); // Clear with spaces
lcd.setCursor(byte_idx, 0);
lcd.cursor();
for (int bit_idx = 0; bit_idx < 8; bit_idx++) {
bool tx_bit = tx_byte & (0x80 >> bit_idx);
lcd.noCursor();
lcd.setCursor(bit_idx * 2, 1); // Adjust position for readability
lcd.print(tx_bit ? "10" : "01"); // High-Low for "1", Low-High for "0"
lcd.setCursor(byte_idx, 0);
lcd.cursor();
}
message[0] = datalength;
man.transmitArray(datalength, message);
moo = ++moo % 2;
digitalWrite(TX_PIN, moo);
delay(800);
datalength++;
if(datalength>18) datalength=2;
}