Kode til bilene 2


//motor A connected between A01 and A02
//motor B connected between B01 and B02

int STBY = 10; //standby STBY

//Motor A
int PWMA = 3; //Speed control PWMA
int AIN1 = 9; //Direction AIN1
int AIN2 = 8; //Direction AIN2

//Motor B
int PWMB = 5; //Speed control PWMB
int BIN1 = 11; //Direction BIN1
int BIN2 = 12; //Direction BIN2

const int MOTOR1 = 1;
const int MOTOR2 = 2;

void setup(){
pinMode(STBY, OUTPUT);

pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);

pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
}
void drive(int motor, int speed){

digitalWrite(STBY, HIGH); //disable standby

boolean inPin1 = LOW;
boolean inPin2 = HIGH;
if(speed > 0){
inPin1 = HIGH;
inPin2 = LOW;
}

speed = min(abs(speed),255);

if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}
else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}

void loop(){
//her skal koden deres stå.
}


Leave a Reply