0% found this document useful (0 votes)
47 views4 pages

Codigo Spinner

The document defines variables to control the pins on a motor controller board to drive two motors and an arm. It sets the motor pin variables as outputs in setup and uses if/else statements in loop to control the motors based on serial input values - driving forward or backward, turning left or right, stopping, or raising/lowering the arm.
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)
47 views4 pages

Codigo Spinner

The document defines variables to control the pins on a motor controller board to drive two motors and an arm. It sets the motor pin variables as outputs in setup and uses if/else statements in loop to control the motors based on serial input values - driving forward or backward, turning left or right, stopping, or raising/lowering the arm.
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/ 4

int m1a = 3;  

         //Motor 1, pin 10 del arduino va al pin 15 del


L293B.
int m1b = 4;             //Motor 1, pin 9 del arduino va al pin 10 del
L293B.
int m2a = 5;            //Motor 2, pin 12 DEL arduino va al pin 2 del L293B.
int m2b = 6;
int arma =2 ;           //Motor 2, pin 11 del arduino va al pin 7 del L293B.
char val;

void setup()
{  
pinMode(m1a, OUTPUT);  // Digital pin 10 set as output Pin
pinMode(m1b, OUTPUT);  // Digital pin 9 set as output Pin
pinMode(m2a, OUTPUT);  // Digital pin 12 set as output Pin
pinMode(m2b, OUTPUT);
pinMode(arma, OUTPUT) ;
 // Digital pin 11 set as output Pin
Serial.begin(9600);
}

void loop()
{
  while (Serial.available() > 0)
  {
  val = Serial.read();
  Serial.println(val);
  }

  if( val == 'F')                   // Hacia adelante


    {
      digitalWrite(m1a, HIGH);
      digitalWrite(m1b, LOW);
      digitalWrite(m2a, HIGH);
      digitalWrite(m2b, LOW);  
    }
  else if(val == 'B')              // Hacia atras
    {
      digitalWrite(m1a, LOW);
      digitalWrite(m1b, HIGH);
      digitalWrite(m2a, LOW);
      digitalWrite(m2b, HIGH);
    }
 
    else if(val == 'L')             // Izquierda
    {
    digitalWrite(m1a, LOW);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, HIGH);
    digitalWrite(m2b, LOW);
    }
    else if(val == 'R')              //Derecha
    {
    digitalWrite(m1a, HIGH);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, LOW);
    digitalWrite(m2b, LOW);
    }
      else if(val == 'S')               //Stop - Pare, Carrito detenido
    {
    digitalWrite(m1a, LOW);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, LOW);
    digitalWrite(m2b, LOW);
    }
    if( val == 'W')               //Stop - Pare, Carrito detenido
    {
    digitalWrite(arma, HIGH);
    }
    if(val == 'w')               //Stop - Pare, Carrito detenido
    {
    digitalWrite(arma, LOW);
}}
int m1a = 3;            //Motor 1, pin 10 del arduino va al pin 15 del
L293B.
int m1b = 4;             //Motor 1, pin 9 del arduino va al pin 10 del
L293B.
int m2a = 5;            //Motor 2, pin 12 DEL arduino va al pin 2 del L293B.
int m2b = 6;
int arma =2 ;           //Motor 2, pin 11 del arduino va al pin 7 del L293B.
char val;

void setup()
{  
pinMode(m1a, OUTPUT);  // Digital pin 10 set as output Pin
pinMode(m1b, OUTPUT);  // Digital pin 9 set as output Pin
pinMode(m2a, OUTPUT);  // Digital pin 12 set as output Pin
pinMode(m2b, OUTPUT);
pinMode(arma, OUTPUT) ;
 // Digital pin 11 set as output Pin
Serial.begin(9600);
}

void loop()
{
  while (Serial.available() > 0)
  {
  val = Serial.read();
  Serial.println(val);
  }

  if( val == 'F')                   // Hacia adelante


    {
      digitalWrite(m1a, HIGH);
      digitalWrite(m1b, LOW);
      digitalWrite(m2a, HIGH);
      digitalWrite(m2b, LOW);  
    }
  else if(val == 'B')              // Hacia atras
    {
      digitalWrite(m1a, LOW);
      digitalWrite(m1b, HIGH);
      digitalWrite(m2a, LOW);
      digitalWrite(m2b, HIGH);
    }
 
    else if(val == 'L')             // Izquierda
    {
    digitalWrite(m1a, LOW);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, HIGH);
    digitalWrite(m2b, LOW);
    }
    else if(val == 'R')              //Derecha
    {
    digitalWrite(m1a, HIGH);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, LOW);
    digitalWrite(m2b, LOW);
    }
      else if(val == 'S')               //Stop - Pare, Carrito detenido
    {
    digitalWrite(m1a, LOW);
    digitalWrite(m1b, LOW);
    digitalWrite(m2a, LOW);
    digitalWrite(m2b, LOW);
    }
    if( val == 'W')               //Stop - Pare, Carrito detenido
    {
    digitalWrite(arma, HIGH);
    }
    if(val == 'w')               //Stop - Pare, Carrito detenido
    {
    digitalWrite(arma, LOW);
}}

You might also like