avr: prellfreier taster in C

mit einem taster 4 befehle durchtoggeln

#define F_CPU 1e6
#include <util/delay.h>
#include <avr/io.h>
#include <stdio.h>
int main(void)
{
 char a=0;
 DDRD = 0x60;     
   PORTD = 0x00;    

   while(1)
 {

     if (PIND & (1<<PIND2)) {

  if (a==0) {PORTD = 0x20;a=1;}
  
  else if (a==1) {PORTD = 0x40;a=2;}

  else if (a==2) {PORTD = 0x60;a=3;}

  else if (a==3) {PORTD = 0x00;a=0;}
  
  _delay_ms(150);

  while (PIND & (1<<PIND2)) {}

 
  }

 

 }

 
}


Comments are closed.