Manchester Encoding and Decoding

Greetings every one

I wrote the two manchester encoding and decoding codes bellow. I tested them suing two ARDUINOs and they both worked for DC. I used simple 8 switches to feed the inputs of the transmitting arduino and fed the 8 outputs of the receivng arduino to LEDs and it worked great. However, in my project I need to transmit audio signal which I already converted it to 8-bit . My question is how to controll the frequancy of the transmission and receiving. by the way, this is my first time I have ever used arduino in any of my projects.

[#include <Manchester.h>

/*

  Manchester Transmitter example
  
  In this example transmitter will send one 16 bit number per transmittion

  try different speeds using this constants, your maximum possible speed will 
  depend on various factors like transmitter type, distance, microcontroller speed, ...

  MAN_300 0
  MAN_600 1
  MAN_1200 2
  MAN_2400 3
  MAN_4800 4
  MAN_9600 5
  MAN_19200 6
  MAN_38400 7


*/
#define TX_PIN 4  //pin where your transmitter is connected

#define D0 5
#define D1 6
#define D2 7
#define D3 8
#define D4 9
#define D5 10
#define D6 11
#define D7 12

int a  = 0;
int a0 = 0;
int a1 = 0;
int a2 = 0;
int a3 = 0;
int a4 = 0;
int a5 = 0;
int a6 = 0;
int a7 = 0;



void setup() {
  pinMode(D0, INPUT);
  pinMode(D1, INPUT);
  pinMode(D2, INPUT);
  pinMode(D3, INPUT);
  pinMode(D4, INPUT);
  pinMode(D5, INPUT);
  pinMode(D6, INPUT);
  pinMode(D7, INPUT);
  
  man.workAround1MhzTinyCore(); //add this in order for transmitter to work with 1Mhz Attiny85/84
  man.setupTransmit(TX_PIN, 1);
 
 
}

void loop() {
 
   a0=digitalRead(D0);
  a1=digitalRead(D1);
  a2=digitalRead(D2);
  a3=digitalRead(D3);
  a4=digitalRead(D4);
  a5=digitalRead(D5);
  a6=digitalRead(D6);
  a7=digitalRead(D7);
  
  a=a0+2*a1+4*a2+8*a3+16*a4+32*a5+64*a6+128*a7;
  
  man.transmit(a);


}]

manchester_receiver.ino (2 KB)

manchester_transmitter.ino (1.27 KB)

   if (a7==1)
  {
    digitalWrite(D7,HIGH);
  }
  else
  { digitalWrite(D7,LOW);
  }

Aren't you just writing the value in a7 to D7? You don't need 8 lines of code to do that (8 times).

Please re-edit your post to use code-tags for your code, or no-one will bother to
read it.

In manchester encoding and decoding, it takes a number of 8 bits as 1 number transmit it and receive it. This code is actualy a combining of two. one that does the manchester and one that reads port D and write port D

which means it takes the 8 bits from A0 to A7 and combineit and save it as one data. after the transmission it does the opisot. it takes that one date and change it to 8- bit output from A0 to A7.

I could have used
PORTD maps to Arduino digital pins 0 to 7

DDRD - The Port D Data Direction Register - read/write

PORTD - The Port D Data Register - read/write

PIND - The Port D Input Pins Register - read only

but unfortunately I did not get how to use it in the code

I have re-edited the post so you can see one of the codes.

What I need the arduino for my project is to take 8-bit input as parallel, transmit it as series, receive it and give it as parallel output.

My project:

Take an analog signal and transmit it throw optical link ( LED or LD). That most be done throw only transmitter only.

Rather than read and write the ports bit by bit, you can use "direct port manipulation". For example, all of your code that transfers the contents of variable a to PORTD bit by bit can be done in just one line as follows:

PORTD = a;

Likewise, you can read PORTD in parallel and transfer its contents to a variable a as follows:

a = PIND;

Of course, for those operations, all the pins of PORTD have to be set to input or output, as appropriate. See Arduino Reference - Arduino Reference