Optocouplers on the hexabusplug

ravinrabbid edited this page Oct 10, 2011 · 2 revisions
Clone this wiki locally

Simple output circuit switching an LED

hexbaus-optocoupler-output

  • Set pin direction to output, e.g. DDRA |= (1<<PA0);
  • Setting pin in port register to HIGH will turn on the LED; setting it to LOW will turn it off.

PORTA |= (1<<PA0); //Turn LED on

PORTA &= ~(1<<PA0); //Turn LED off

Simple input circuit

hexbaus-optocoupler-output

  • Activate internal pullup or add an external pullup to the circuit! PORTA |= (1<<PA1);
  • If the pin bit in PINA is set, the switch is open, if it is clear the switch is closed.