Advertisement
tiodocomputador

Joystick + Motor de Passo

May 18th, 2015
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. /*
  2.   Motor de Passo Mitsumi 5 terminais.
  3.  Gira o motor em funcao da leitura de um potenciometro.
  4.  Autor: http://cyberohm.com
  5.  Apoio: http://www.labdegaragem.com
  6.  */
  7.  
  8. int matriz[8][4] =
  9. {
  10.   {
  11.     0,0,0,1                              }
  12.   ,
  13.   {
  14.     0,0,1,1                              }
  15.   ,
  16.   {
  17.     0,0,1,0                              }
  18.   ,
  19.   {
  20.     0,1,1,0                              }
  21.   ,
  22.   {
  23.     0,1,0,0                              }
  24.   ,
  25.   {
  26.     1,1,0,0                              }
  27.   ,
  28.   {
  29.     1,0,0,0                              }
  30.   ,
  31.   {
  32.     1,0,0,1                              }
  33.  
  34. };
  35.  
  36. int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
  37.   int t=10;
  38. int x;
  39. int y;
  40. int count;
  41.  
  42. void setup()
  43. {                
  44.   Serial.begin(9600);
  45.   pinMode(2, OUTPUT);  
  46.   pinMode(3, OUTPUT);
  47.   pinMode(4, OUTPUT);
  48.   pinMode(5, OUTPUT);
  49. }
  50.  
  51. void loop()
  52. {
  53.   // read the analog in value:
  54.   int  sensorValue = analogRead(analogInPin);            
  55.   // map it to the range of the analog out:
  56.   int  outputValue = map(sensorValue, 0, 1023, 0, 12);  
  57.   // change the analog out value:
  58.  
  59.   {
  60.     while(count<outputValue)
  61.     {
  62.       for (x=0; x<8; x++)
  63.       {
  64.         for (y=0; y<4; y++)
  65.         {
  66.           digitalWrite((y+2), matriz[x][y]);
  67.         }
  68.         delay(t);
  69.       }
  70.       count++;
  71.     }
  72.     while(count>outputValue)
  73.     {
  74.       for (x=7; x>=0; x--)
  75.       {
  76.         for (y=0; y<4; y++)
  77.         {
  78.           digitalWrite((y+2), matriz[x][y]);
  79.         }
  80.         delay(t);
  81.       }
  82.       count--;
  83.     }
  84.   }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement