I have a code here meant to control 2 servos through an app by sending serial codes I'm having issues with getting it to work in using aada fruit trinket 3v a hm-10 BT component and 2 linear servos I think I may not have defined the pinouts for the Rx tx I hope this is the issue but if there is anything else i need help figuring it out.
#include <Adafruit_SoftServo.h> // SoftwareServo (works on non PWM pins)
#include <SoftwareSerial.h>
#define SERVO0PIN 0
#define SERVO1PIN 1
int moveAmount = 1; // change this value to change speed of servo
int servoPos = 0; // variable for servo position
const int x=0;
const int y=1;
int w =1001;
SoftwareSerial BTSerial(x,y); //RX|TX
Adafruit_SoftServo myServo1;
Adafruit_SoftServo myServo2;//create servo object
void setup() {
BTSerial.begin(9600); // default baud rate
// Set up the interrupt that will refresh the servo for us automagically
OCR0A = 0xAF; // any number is OK
TIMSK |= _BV(OCIE0A); // Turn on the compare interrupt (below!)
myServo1.attach(SERVO0PIN);
myServo2.attach(SERVO1PIN); // Attach the servo to pin 0 on Trinket
myServo1.write(90);
myServo2.write(5); // Tell servo to go to position per quirk
delay(15); // Wait 15ms for the servo to reach the position
}
void loop() {
if(BTSerial.available()== w)
myServo2.write(10);
delay(20);
myServo1.write(servoPos);
servoPos = servoPos + moveAmount;
if (servoPos == 0 || servoPos == 180){
moveAmount = -moveAmount;
}
delay(15); // waits 15ms for the servo to reach the position
if(BTSerial.available()== w * 7)
myServo2.write(0);
delay(20);
if(BTSerial.available()== w * 2)
myServo2.write(20);
delay(20);
myServo1.write(servoPos);
servoPos = servoPos + moveAmount;
if (servoPos == 0 || servoPos == 180){
moveAmount = -moveAmount;
}
delay(15); // waits 15ms for the servo to reach the position
if(BTSerial.available()== w * 7)
myServo2.write(0);
delay(20);
if(BTSerial.available()== w *3)
myServo2.write(30);
delay(20);
myServo1.write(servoPos);
servoPos = servoPos + moveAmount;
if (servoPos == 0 || servoPos == 180){
moveAmount = -moveAmount;
}
delay(15); // waits 15ms for the servo to reach the position
if(BTSerial.available()== w * 7)
myServo2.write(0);
delay(20);
if(BTSerial.available()== w * 4)
myServo2.write(40);
delay(20);
myServo1.write(servoPos);
servoPos = servoPos + moveAmount;
if (servoPos == 0 || servoPos == 180){
moveAmount = -moveAmount;
}
delay(15); // waits 15ms for the servo to reach the position
if(BTSerial.available()== w * 7)
myServo2.write(0);
delay(20);
if(BTSerial.available()== w *5)
myServo2.write(50);
delay(20);
myServo1.write(servoPos);
servoPos = servoPos + moveAmount;
if (servoPos == 0 || servoPos == 180){
moveAmount = -moveAmount;
}
delay(15); // waits 15ms for the servo to reach the position
if(BTSerial.available()== w * 7)
myServo2.write(0);
delay(20);
if(BTSerial.available()== w * 6)
myServo2.write(6w);
delay(20);
myServo1.write(servoPos);
servoPos = servoPos + moveAmount;
if (servoPos == 0 || servoPos == 180){
moveAmount = -moveAmount;
}
delay(15); // waits 15ms for the servo to reach the position
if(BTSerial.available()== w * 7)
myServo2.write(0);
delay(20);
}
volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect) {
// this gets called every 2 milliseconds
counter += 2;
// every 20 milliseconds, refresh the servos!
if (counter >= 20) {
counter = 0;
myServo1.refresh();
}
}
Moderator edit: [code] [/code] tags added.