0% found this document useful (0 votes)
29 views5 pages

Codigo de Dos Mo Tores

The document describes Arduino code for controlling motors and LEDs. It includes code for controlling 2 motors together or independently based on serial input. It also includes code for controlling 4 motors or 2 LEDs independently based on mapped serial input values. The code sets motor and LED pins as outputs, reads serial input to set speed values, and uses if/else statements to control analogWrite outputs based on the input state character.

Uploaded by

Edgar Monge
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)
29 views5 pages

Codigo de Dos Mo Tores

The document describes Arduino code for controlling motors and LEDs. It includes code for controlling 2 motors together or independently based on serial input. It also includes code for controlling 4 motors or 2 LEDs independently based on mapped serial input values. The code sets motor and LED pins as outputs, reads serial input to set speed values, and uses if/else statements to control analogWrite outputs based on the input state character.

Uploaded by

Edgar Monge
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/ 5

CODIGO DE DOS MO TORES

int motorA = 5;
int motorB = 6;
int estado='g'
int vel;
void setup() {
Serial.begin(9600);
pinMode(motorA, OUTPUT);
pinMode(motorB, OUTPUT);
}
void loop() {
while(Serial.available() > 0){
int valor = Serial.read() - 48;
valor = map(valor, 0, 100, 0, 254);
analogWrite(motorA, valor);
analogWrite(motorB, valor);
vel = (valor*.75) ;
delay (100);}
if(estado=='a'){
analogWrite ( motorA,vel);
analogWrite ( motorB,vel);
}

if(estado=='b'){
analogWrite (motorA,valor);
analogWrite(motorB, vel);

}
if(estado=='c'){
analogWrite ( motorA,);
analogWrite(motorB, );

}
if(estado=='d'){
analogWrite ( motorA,vel);
analogWrite(motorB, valor);
}
if(estado=='e'){
analogWrite(motorA,valor);
analogWrite(motorB, valor);
}
}
Código de los cuatro motores
int motorA = 5;
int motorB = 6;
int motorA1 = 9;
int motorB2 = 10;
int estado='g';
int vel, valor;
void setup() {
Serial.begin(9600);
pinMode(motorA, OUTPUT);
pinMode(motorB, OUTPUT);
pinMode(motorA1, OUTPUT);
pinMode(motorB2, OUTPUT);
}
void loop() {
while (Serial.available() > 0) {
valor = Serial.read() - 48;
valor = map(valor, 0, 100, 0, 254);
analogWrite(motorA, valor);
analogWrite(motorB, valor);
analogWrite(motorA1, valor);
analogWrite(motorB2, valor);
vel = (valor * .75) ;
delay (100);
}
if (estado == 'a') {
analogWrite ( motorA, vel);
analogWrite ( motorB, vel);
analogWrite(motorA1, valor);
analogWrite(motorB2, valor);
}

if (estado == 'b') {
analogWrite (motorA, valor);
analogWrite(motorB, vel);
analogWrite(motorA1, valor);
analogWrite(motorB2, vel);

}
if (estado == 'c') {
analogWrite ( motorA, 125);
analogWrite(motorB, 100);
analogWrite(motorA1, 125);
analogWrite(motorB2, 100);

}
if (estado == 'd') {
analogWrite ( motorA, vel);
analogWrite(motorB, valor);
analogWrite(motorA1, vel);
analogWrite(motorB2, valor);

}
if (estado == 'e')
{
analogWrite(motorA, valor);
analogWrite(motorB, valor);
analogWrite(motorA1, vel);
analogWrite(motorB2, vel);
}
}
Control de velocidad dos motores independiente
int LED = 5;
int LED1 = 6;
int estado='g';
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(LED1, OUTPUT);
}

void loop() {
while(Serial.available() > 0)
if (estado == 'a') {
int valor = Serial.read() - 48;
valor = map(valor, 0, 100, 0, 254);
analogWrite(LED, valor);
analogWrite(LED1, valor);
delay (100);
}
if (estado == 'b') {
int valor = Serial.read() - 48;
valor = map(valor, 0, 100, 0, 254);
analogWrite(LED, valor);
analogWrite(LED1, valor);
delay (100);
}
}

You might also like