Skip to content

Instantly share code, notes, and snippets.

@jazzyjackson
Created May 25, 2019 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzyjackson/baeed0f1df46e185949d5b3b38008633 to your computer and use it in GitHub Desktop.
Save jazzyjackson/baeed0f1df46e185949d5b3b38008633 to your computer and use it in GitHub Desktop.
#include <Adafruit_TiCoServo.h>
class MotorState {
private:
Adafruit_TiCoServo _servo_backdrop;
Adafruit_TiCoServo _servo_stage;
public:
MotorState();
void init(Adafruit_TiCoServo *servB, Adafruit_TiCoServo *servS);
void updateMotors(int backdrop, int stage);
};
MotorState::MotorState(){}
void MotorState::init(Adafruit_TiCoServo *servB, Adafruit_TiCoServo *servS){
_servo_backdrop = *servB;
_servo_stage = *servS;
}
void MotorState::updateMotors(int backdrop, int stage){
int s = constrain(map(stage, 0, 1023, 500, 2500), 500, 2500);
int b = constrain(map(backdrop, 0, 1023, 500, 2500), 500, 2500);
_servo_stage.write(s);
delay(20);
_servo_backdrop.write(b);
}
#include "motors.h"
#include <Adafruit_TiCoServo.h>
Adafruit_TiCoServo servo_backdrop;
Adafruit_TiCoServo servo_stage;
MotorState motorState;
void setup() {
// put your setup code here, to run once:
servo_backdrop.attach(9);
servo_stage.attach(10);
motorState.init(&servo_backdrop, &servo_stage);
}
void loop() {
// put your main code here, to run repeatedly:
motorState.updateMotors(analogRead(A0), analogRead(A1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment