Code:also hier ist der IR Sensor code #define __AVR_ATmega88__ #include <avr/io.h> //#include <iom88.h> long i; #define STATSLED0_ON (PORTC |= 1<<PC0) #define STATSLED0_OFF (PORTC &= ~(1<<PC0)) #define STATSLED1_ON (PORTC |= 1<<PC1) #define STATSLED1_OFF (PORTC &= ~(1<<PC1)) #define GET_IRSEN_RIGHT (PIND & 1<<PD4) #define GET_IRSEN_LEFT (PIND & 1<<PD3) void turnLEFTforward(){ // Motor 1 stop PORTD |= 1<<PD6; PORTD |= 1<<PD7; // Motor 2 Forward PORTB |= 1<<PB2; PORTB &= ~(1<<PB1); } void turnRIGHTforward(){ // Motor 1 Forward PORTD |= 1<<PD6; PORTD &= ~(1<<PD7); // Motor 2 stop PORTB |= 1<<PB2; PORTB |= 1<<PB1; } int main(){ DDRD = 1<<PD6 | 1<<PD7; // PD6 PD7 Output Motor1; DDRB = 1<<PB1 | 1<<PB2; // PB1 PB2 Output Motor2; DDRD &= ~(1<<PD3 | 1<<PD4); // PD3 PD4 Input IR Sensors; DDRC = 1<<PC0 | 1<<PC1; // PC0 PC1 Output STATSLED0 & 1; //PORTD &= ~(1<<PD6); //PORTD &= ~(1<<PD7); // (!)= schwarz & () = weiss // GET_IRSEN_RIGHT = STATSLED1 // GET_IRSEN_LEFT = STATSLED0 while(1){ if(! GET_IRSEN_LEFT && ! GET_IRSEN_RIGHT){ turnRIGHTforward(); STATSLED0_OFF; STATSLED1_OFF; } else if( ! GET_IRSEN_LEFT && GET_IRSEN_RIGHT){ turnRIGHTforward(); STATSLED0_OFF; STATSLED1_ON; } else if( GET_IRSEN_LEFT && ! GET_IRSEN_RIGHT){ turnLEFTforward(); STATSLED0_ON; STATSLED1_OFF; } else if( GET_IRSEN_LEFT && GET_IRSEN_RIGHT){ turnLEFTforward(); STATSLED0_ON; STATSLED1_ON; } //PORTC = 1<<PC5; //PORTC = 0<<PC5; } }
Lesezeichen