0% found this document useful (0 votes)
8 views

Programacion

Uploaded by

randalyashiro123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Programacion

Uploaded by

randalyashiro123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <SoftwareSerial.

h>

SoftwareSerial Bluetooth(0, 1); // RX, TX

// Pines del puente H

const int in1 = 2;

const int in2 = 3;

const int in3 = 4;

const int in4 = 5;

void setup() {

// Configurar pines como salidas

pinMode(in1, OUTPUT);

pinMode(in2, OUTPUT);

pinMode(in3, OUTPUT);

pinMode(in4, OUTPUT);

// Iniciar la comunicación serie

Serial.begin(9600);

Bluetooth.begin(9600);

void loop() {

if (Bluetooth.available()) {

char command = Bluetooth.read();

controlMotors(command);

}
void controlMotors(char cmd) {

switch (cmd) {

case '2': // Adelante

digitalWrite(in1, HIGH);

digitalWrite(in2, LOW);

digitalWrite(in3, HIGH);

digitalWrite(in4, LOW);

break;

case '3': // Atrás

digitalWrite(in1, LOW);

digitalWrite(in2, HIGH);

digitalWrite(in3, LOW);

digitalWrite(in4, HIGH);

break;

case '4': // Izquierda

digitalWrite(in1, LOW);

digitalWrite(in2, HIGH);

digitalWrite(in3, HIGH);

digitalWrite(in4, LOW);

break;

case '5': // Derecha

digitalWrite(in1, HIGH);

digitalWrite(in2, LOW);

digitalWrite(in3, LOW);

digitalWrite(in4, HIGH);

break;

case '6': // Detener

digitalWrite(in1, LOW);

digitalWrite(in2, LOW);

digitalWrite(in3, LOW);

digitalWrite(in4, LOW);
break;

default:

break;

You might also like