Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* FILE: Posição Step
- DATE: 17/11/15
- VERSION: 0.1
- AUTHOR: Rui
- */
- #define DIR_PIN 8 //Connect to drive modules 'direction' input.
- #define STEP_PIN 9 //Connect to drive modules 'step' or 'CLK' input.
- /* Set the analogue pin the potentiometer will be connected to. */
- #define POT_PIN A0
- int Pos = 0; // inicial position off stepper
- int Speed, Val;
- unsigned int Angulo;
- byte Vel = 10;
- byte Sample = 20;
- //---------------------------------
- void setup()
- {
- Serial.begin(9600);
- pinMode(DIR_PIN, OUTPUT);
- pinMode(STEP_PIN, OUTPUT);
- }
- //--------------------------------
- void loop()
- {
- for (unsigned int j = 0; j<Sample ; j++)
- {
- Val = Val = analogRead(POT_PIN);
- delay(1);
- }
- Val + Val /Sample;
- Angulo = map(Val,0,1023,1,100);
- Pos = Angulo-Pos;
- if (Pos>0)
- {
- digitalWrite(DIR_PIN,HIGH);
- for (unsigned i = 0 ; i<abs(Pos) ; i++)
- {
- digitalWrite(STEP_PIN,HIGH);
- delay(Vel);
- digitalWrite(STEP_PIN,LOW);
- delay(Vel);
- }
- }
- else
- {
- digitalWrite(DIR_PIN,LOW);
- for (unsigned i = 0 ; i<abs(Pos) ; i++)
- {
- digitalWrite(STEP_PIN,HIGH);
- delay(Vel);
- digitalWrite(STEP_PIN,LOW);
- delay(Vel);
- }
- }
- Pos = Angulo;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement