Interboard Communication Question

Hey there, I am Very new to Arduino, My class is currently programming the Arduino R3 using the language C.

We are trying to wire two boards together and one being a sender and other being a receiver.

The Sender sends the 8 bit input from the pressure sensor to the receiver board to turn on the appropriate LED lighting.

Instruction as follow:

We will use a single GPIO pin on each board to do a very simple serial communication link between the boards. This will require the use of a timer as well. In short, when a transmitter is ready to send data it will send a single start bit (“1”). This will be followed by an 8-bit data value. The transmitter will change the value of the GPIO line on the overflow of the timer. The receiver will be looking for the start bit and will start a timer once received to get each bit as it comes in.

My question is: how would i go about writing the int main() to sent the analog value to the other board??

The following is my current code:

main.c
{
   int sending = 0;

   ISR(TIMER0_OVF_vect)
   {
      static int count = 0;

      if (sending)
      {
         shift_to_next_bit <<= 1;
         count++;
      }
      if (count >= 9)
      {
          sending = 0;
      }
   }

   ISR(TIMER0_COMPA_vect)
   {
      PORTB &= ~(1 << DDB5);
   }

   void SendData();

   int main()
   {
      uint8_t value;
      while(1)
      {
          value = ADCH;
          //what to do?
      }
      
     return 0;
   }

   void SendData()
   {
      PORTB |= 0x20; //using Digital pin 13
      sending = 1;
      while(sending)
      {
      }
   }
}

how would i go about writing the int main() to sent the analog value to the other board??

When programming an Arduino it is unusual to write your own main() function. Have you been explicitly told to do this or could you use the more normal Arduino setup() and loop() functions in the Arduino IDE as the basis for your program ?

You [u]can[/u] write your own main() function if you really have to but you will face extra difficulties if you do.

xenroid: We will use a single GPIO pin on each board to do a very simple serial communication link between the boards. This will require the use of a timer as well. In short, when a transmitter is ready to send data it will send a single start bit (“1”). This will be followed by an 8-bit data value. The transmitter will change the value of the GPIO line on the overflow of the timer. The receiver will be looking for the start bit and will start a timer once received to get each bit as it comes in.

My question is: how would i go about writing the int main() to sent the analog value to the other board??

Taking things in reverse order. You are sending digital values, not analog values.

What you describe is exactly how normal Serial communication works. You may be interested in my Yet Another Software Serial

It would be much simpler if you use a second I/O connection to act as a clock signal to synchronize the communication so that there would be no need for accurate timers.

...R

Thank you guys for your replies, I have Solved the problem and the boards are working correctly, again, thank you @Robin2 and @UKHeliBob for your help.