The servo works using the example code from its library but when I add code from the radio head library to control a 433mhz rf module it stops working, here is the code I am using
#include <PWMServo.h>
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
String bar_state = "close"; //bar state open or close
String prev_bar_state = "close";
String msgReicieved = "";//message from reiciver
const int servo_rotation = 180 ;//amount the servo needs to move to completly move bar
const int servo_pin = 9;
int pos = 0; // variable to store the servo position
PWMServo Lock_servo; // create servo object called "servo"
RH_ASK driver (2000,4,11,3);// (speed,riecieve,transmit,push to talk)
void setup() {
Serial.begin(9600);
Lock_servo.attach(SERVO_PIN_A); // (pin 9)
if (!driver.init())
Serial.println("init failed");
}
void loop() {
Serial.println("seffgdfg ");
uint8_t buf[12];//amount of characters that is goign to be recieved
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) {
int i;
// Message with a good checksum received, dump it.
Serial.print("Message: ");
msgReicieved = (char*)buf;
Serial.println(msgReicieved);
}
for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees, 1 degree steps
Lock_servo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
Lock_servo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
when I delete these lines from the setup it starts working again
if (!driver.init())
Serial.println("init failed");
but those lines of code are needed to run the RF module, anyone know what is going on?