Created
May 25, 2019 06:25
-
-
Save jazzyjackson/baeed0f1df46e185949d5b3b38008633 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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