Código Aula 11/15
#include
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution // for your motor // initialize the stepper library on pins 8 through 11: Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11); void setup() { // set the speed at 60 rpm: myStepper.setSpeed(30); // initialize the serial port: Serial.begin(9600); } void loop() { // step one revolution in one direction: Serial.println("clockwise"); myStepper.step(stepsPerRevolution); delay(500); // step one revolution in the other direction: Serial.println("counterclockwise"); myStepper.step(-stepsPerRevolution); delay(500); }
Interface de controle para motor de passo:
/**** Interface para o controle de motor de passo ****/ //Carrega a biblioteca LiquidCrystal #include
//Define os pinos que serão utilizados para ligação ao display LiquidCrystal lcd(3, 2, 7, 6, 5, 4); #include
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution // for your motor // initialize the stepper library on pins 8 through 11: Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11); //------------------------------------------------------ Variáveis para a leitura dos botões --------------------------------------------------// int LeituraBotoes = 0; //-----------------------------------------------------Variáveis para a condição do Botão SELECT ---------------------------------------------// int Para = 0; int CliquesBotaoSelect = 0; //-----------------------------------------------------Variáveis para a condição do Botão UP -----------------------------------------------// int Para2 = 0; int PassosSentidoHorario = 0; //------------------------------------------------------Variáveis para a condição do Botão DOWN ------------------------------------------------// int Para3 = 0; int PassosSentidoAntiHorario = 0; void setup() { // set the speed at 60 rpm: myStepper.setSpeed(30); // initialize the serial port: Serial.begin(9600); //Define o número de colunas e linhas do LCD lcd.begin(16, 2); } void loop() { //---------------------------------------------------------- Para a leitura dos botões ------------------------------------------------------// LeituraBotoes = analogRead(A2); Serial.println(LeituraBotoes); Serial.println(CliquesBotaoSelect); //-------------------------------------------- Incremento de variáveis a cada clique do botão SELECT -----------------------------------------// if(LeituraBotoes >= 700 && LeituraBotoes <= 750 && Para == 0){ Para = 1; } if(LeituraBotoes >= 1000 && Para == 1){ CliquesBotaoSelect++; Para = 0; } //-------------------------------------------- Incremento de variáveis a cada clique do botão LEFT -----------------------------------------// if(LeituraBotoes >= 460 && LeituraBotoes <= 499 ){ myStepper.step(PassosSentidoHorario); } //-------------------------------------------- Incremento de variáveis a cada clique do botão HIGTH -----------------------------------------// if(LeituraBotoes >= 0 && LeituraBotoes <= 10){ myStepper.step(-PassosSentidoAntiHorario); } //------------------------------------------------------------------ Primeira Tela ------------------------------------------------------------// if (CliquesBotaoSelect == 0){ //-------------------------------------------- Incremento de variáveis a cada clique do botão UP -----------------------------------------// if(LeituraBotoes >= 100 && LeituraBotoes <= 150 && Para2 == 0){ Para2 = 1; } if(LeituraBotoes >= 1000 && Para2 == 1){ PassosSentidoHorario = PassosSentidoHorario+10; Para2 = 0; } //-------------------------------------------- Incremento de variáveis a cada clique do botão Down -----------------------------------------// if(LeituraBotoes >= 300 && LeituraBotoes <= 340 && Para3 == 0){ Para3 = 1; } if(LeituraBotoes >= 1000 && Para3 == 1){ PassosSentidoHorario = PassosSentidoHorario-10; Para3 = 0; } //Limpa a tela lcd.clear(); // C L lcd.setCursor(0, 0); lcd.print("Passos Horario"); // C L lcd.setCursor(0, 1); lcd.print(PassosSentidoHorario); delay(50);//Tempo para a exibição no display não ficar falhada. } //------------------------------------------------------------------ Segunda Tela------------------------------------------------------------// if (CliquesBotaoSelect == 1){ //-------------------------------------------- Incremento de variáveis a cada clique do botão UP -----------------------------------------// if(LeituraBotoes >= 100 && LeituraBotoes <= 150 && Para2 == 0){ Para2 = 1; } if(LeituraBotoes >= 1000 && Para2 == 1){ PassosSentidoAntiHorario = PassosSentidoAntiHorario+10; Para2 = 0; } //-------------------------------------------- Incremento de variáveis a cada clique do botão Down -----------------------------------------// if(LeituraBotoes >= 300 && LeituraBotoes <= 340 && Para3 == 0){ Para3 = 1; } if(LeituraBotoes >= 1000 && Para3 == 1){ PassosSentidoAntiHorario = PassosSentidoAntiHorario-10; Para3 = 0; } //Limpa a tela lcd.clear(); // C L lcd.setCursor(0, 0); lcd.print("Passos Anti H"); // C L lcd.setCursor(0, 1); lcd.print(PassosSentidoAntiHorario); delay(50);//Tempo para a exibição no display não ficar falhada. } if (CliquesBotaoSelect == 2){ CliquesBotaoSelect = 0; } if (PassosSentidoAntiHorario > 400){ PassosSentidoAntiHorario = 400; } if (PassosSentidoAntiHorario < 0){ PassosSentidoAntiHorario = 0; } if (PassosSentidoHorario > 400){ PassosSentidoHorario = 400; } if (PassosSentidoHorario < 0){ PassosSentidoHorario = 0; } }
Página inicial
Assinar:
Postagens (Atom)