• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Sterowanie silnikiem krokowy i dc przy pomocy IR
#1
Witam

Nie mogę dojść końca z równoczesnym sterowaniem silnikiem krokowym oraz dc. Chciałbym aby silnik krokowy wykonywał ciagłą rotecje z regulacją obrotów, do tego regulacja obrotów silnika dc. Na chwilę obecną albo działa ir i silnik dc albo kiedy dział silnik krokowy i dc to po wyłączeniu nie czyta sygnału ir.
Kod:
#include "IRremote.h"

#include <Stepper.h> // Include the header file
// change this to the number of steps on your motor
#define STEPS 64
// create an instance of the stepper class using the steps and pins
Stepper stepper(STEPS, 8, 10, 9, 11);

int receiver = 3;
int Power__ON = 0;

int x;
int w1 = 5; // wiatrak pwm
int val = 0;

IRrecv irrecv(receiver);
decode_results results;

int vel2 = 100; // naped
int vel1 = 150; //wiatrak

void setup()
{
 Serial.begin(9600);
 irrecv.enableIRIn();
// Set the output pins
pinMode(w1, OUTPUT);
 //val = 100;
   
}

void loop()
{
   if (irrecv.decode(&results))
 {
   x = results.value & 0x0000ff;
   Serial.println(results.value, HEX);
   processIR();
   irrecv.resume();
   }
   stepper.step(val+10);
  // irrecv.resume();
}

void processIR()
{
  if (x == 0x3D || x == 0xBB) //ON
  {
//wiatrak
analogWrite(w1, vel1); // Sets speed variable via PWM
stepper.setSpeed(vel2);
}


else if (x == 0x1D || x == 0x7F) //turn off
 {
   Power__ON = Power__ON;
   int x = Power__ON%2;
   Serial.println(x);
   if (x == 0)
   {
     Serial.println("Both Motor goes OFF");
     analogWrite(w1, 0); // Sets speed variable via PWM
     stepper.setSpeed(0);
     stepper.step(0);
}
}
else if (x == 0x57 || x == 0xDB) // vol+
 {
   vel1 = vel1 + 10;
   analogWrite(w1, vel1);
   vel2 = vel2 + 40;
   stepper.setSpeed(vel2);
   
 }
 
  else if (x == 0x1F || x == 0x3B) // vol-
 {
  vel1 = vel1 - 10;
   analogWrite(w1, vel1);
   vel2 = vel2 - 40;
   stepper.setSpeed(vel2);
 }
 
}
 
Bedę wdzięczny za pomoc.
 
Odpowiedź
  


Wiadomości w tym wątku
Sterowanie silnikiem krokowy i dc przy pomocy IR - przez qwert - 26-03-2019, 00:55

Skocz do:


Przeglądający: 1 gości