Pages: [1]   Go Down
Author Topic: Stepper motor problem  (Read 123 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
I am trying to use a stepper motor to actuate a blind with lightwaverf home automation protocol. It is a 4 wire 42BYGHW609 and is  on an L293 based motor shield. It works with the AFmotor library example. However when I try to integrate that into the lightwaverf sketch it will only turn once. I suspect it could be something to do with interrupts but don't know where to begin looking.
Here is the code:
Code:
#include <LwRx.h>
#include <EEPROM.h>
#include <string.h>
#define echo true
#include <AFMotor.h>
AF_Stepper motor(200, 1);
//lwrf code
static byte sideopen[10] = {1,15,0,1,3,2,10,14,9,7};
static byte sideclose[10] = {4,0,0,0,3,2,10,14,9,7};
int matchcounter = 0;

//Msg data
byte msg[10];
byte msglen = 10;

void setup() {
  lwrx_setup(2);
Serial.begin(9600);
Serial.println(F("Set up ok"));
motor.setSpeed(100);  // in rpm   
}
void loop() { 
  if (lwrx_message()) {
    lwrx_getmessage(msg, msglen);   
   if (comparemessage(msg, sideopen) == 10)
    {
     blindup();     
    }
     if (comparemessage(msg, sideclose) == 10)
    {
      blinddown(); 
    }   
  }
}
//compare incoming messages to known codes
int comparemessage (byte * msg, byte * lwrfcommand)
{
  matchcounter = 0;
  for (int i = 0; i < 10; i++)
  {
    if (msg[i] == lwrfcommand[i])
    {
      matchcounter++;
    }
  }
  return matchcounter;
}
void blindup()
{
     motor.step(200, FORWARD, DOUBLE);
}
void blinddown()
{
  motor.step(200, BACKWARD, DOUBLE);
}
Any ideas?
Logged

Pages: [1]   Go Up
Jump to: