Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <AFMotor.h>
  2.  
  3. AF_DCMotor motor(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
  4. int pot = A1; //puerto analogo del motor
  5. int valpot =0; //declaracion del valor del puerto
  6.  
  7.  
  8. // se ejecuta 1 sola vez, al iniciar el programa
  9. void setup() {
  10.  
  11.     pinMode(pot, INPUT);
  12.    
  13.    
  14. }
  15.  
  16. // se repite infinitamente mientras el arduino tenga corriente
  17. void loop() {
  18.  
  19.   valpot= analogRead(pot);
  20.  
  21.   if( valpot >= 0  && valpot <401)
  22.           {
  23.              int indice = map(valpot,400,0,0,255 );
  24.              motor.setSpeed(indice);     // set the speed to 200/255  
  25.              motor.run(BACKWARD);    
  26.            
  27.            
  28.           }      
  29.           else if(valpot > 400  && valpot < 625)
  30.           {
  31.             int indice = map(valpot,401,624,0,255 );
  32.              motor.run(RELEASE);      // stopped
  33.             // the other way
  34.                              
  35.           }
  36.           else if(valpot > 624  && valpot < 1024)
  37.           {
  38.             int indice = map(valpot,625,1023,0,255 );
  39.             motor.run(FORWARD);
  40.              
  41.          }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. }