Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#define potentiometer A0 //10k poten

#define bt_A A1 // derecha boton


#define bt_D A2 // detener Boton
#define bt_R A3 // izquierda boton

#define Ena 11 // Enable1 L298 el PWM del motorxd


#define in1 10 // In1 L298 a derecha
#define in2 9 // In2 L298 a izquierda
int read_ADC =0;
int velocidad;
int set = 0;

void setup() {
// put your setup code here, to run once:
pinMode(potentiometer, INPUT);

pinMode(bt_A, INPUT_PULLUP);
pinMode(bt_D, INPUT_PULLUP);
pinMode(bt_R, INPUT_PULLUP);

pinMode(Ena, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);

void loop() {
// put your main code here, to run repeatedly:
read_ADC = analogRead(potentiometer);
velocidad = map(read_ADC, 0, 1023, 0, 255);

analogWrite(Ena, velocidad);

if(digitalRead (bt_A) == 0){set = 1;}


if(digitalRead (bt_D) == 0){set = 0;}
if(digitalRead (bt_R) == 0){set = 2;}

if(set==0){
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}

if(set==1){
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
}

if(set==2){
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
}

You might also like