0% found this document useful (0 votes)
19 views2 pages

Apendicec PDF

This code controls 4 motors and sends the obtained data through the serial port. It defines variables to control the pulse width modulation (PWM) for each motor from a minimum to maximum value over time. The code increases the PWM value in a loop to gradually increase the motor speed, sends the speed data over serial, then decreases the PWM in another loop to gradually decrease the motor speed.

Uploaded by

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

Apendicec PDF

This code controls 4 motors and sends the obtained data through the serial port. It defines variables to control the pulse width modulation (PWM) for each motor from a minimum to maximum value over time. The code increases the PWM value in a loop to gradually increase the motor speed, sends the speed data over serial, then decreases the PWM in another loop to gradually decrease the motor speed.

Uploaded by

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

ApndiceC

Cdigoutilizadoparacontrolarlos4motoresymandarlosdatosobtenidospormedio
delpuertoserial.

int
int
int
int
int

pulso
act1 =
act2 =
act3 =
act4 =

= 4;
3;
5;
6;
9;

// valores de PWM
int e = 250;
int v= 0;
int vin=130;
// 4 motores a controlar
int a = 0;
int b = 0;
int c = 0;
int d = 0;
//Inclinacin acelermetro
int x1 = 0;
int x2 = 0;
int y1 = 0;
int y2 = 0;

void setup()
{
pinMode(13, OUTPUT); //utilizaremos el LED para saber que el
programa funciona
beginSerial (19200);
Serial.print ("Finished setup\n");
pinMode(pulso, OUTPUT);
}
void loop()
{
digitalWrite(13, LOW); //encendemos el LED (luego lo apagaremos)
digitalWrite(pulso,HIGH);
// For de subida de velocidad
for(v = vin; v <= e; v+=15) // fade in (from min to max)

{
a=v;
b=v;

c=v;
d=v;
analogWrite(act1,
analogWrite(act2,
analogWrite(act3,
analogWrite(act4,
delay(1000);
dimming effect

a);
b);
c);
d);

// sets the value (range from 0 to 255)

// waits for 1 seconds to see the

char buf2[4];
Serial.print ("M.1: ");
Serial.print (itoa(((a*100)/255),
Serial.print ("\t M.2: ");
Serial.print (itoa(((b*100)/255),
Serial.print ("\t M.3: ");
Serial.print (itoa(((c*100)/255),
Serial.print ("\t M.4: ");
Serial.print (itoa(((d*100)/255),
Serial.println ("");
///

buf2, 10));
buf2, 10));
buf2, 10));
buf2, 10));

delay(700);
}
digitalWrite(13, HIGH); //apagar LED
delay(5000);
digitalWrite(13, LOW); //apagar LED

// For de bajada de velocidad


for(v = e; v >=vin; v-=15)
// fade out (from max to min)
{
a=v;
b=v;
c=v;
d=v;
analogWrite(act1,
analogWrite(act2,
analogWrite(act3,
analogWrite(act4,
delay(1000);

a);
b);
c);
d);

char buf2[4];
Serial.print ("M.1: ");
Serial.print (itoa(((a*100)/255),
Serial.print ("\t M.2: ");
Serial.print (itoa(((b*100)/255),
Serial.print ("\t M.3: ");
Serial.print (itoa(((c*100)/255),
Serial.print ("\t M.4: ");
Serial.print (itoa(((d*100)/255),
Serial.println ("");

buf2, 10));
buf2, 10));
buf2, 10));
buf2, 10));

delay(700);
}
}

You might also like