Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* TurntableControl.ino
* Libraries required:
* - Pololu DRV8835 Dual Motor Driver Carrier - https://github.com/raster/drv8835-motor-driver
* - ServoTimer2 Library - http://forum.arduino.cc/index.php?action=dlattach;topic=157400.0;attach=39747
*
* pete@2xlnetworks.com
*
*/
#include <DRV8835DualDriver.h>
DRV8835DualDriver motors;
#include <ServoTimer2.h>
ServoTimer2 servo;
int APin = A4;
int CPin = A5;
int servoPin = 12;
int i = 0;
void setup() {
servo.attach(servoPin);
}
void loop() {
int AReading = 0;
int CReading = 0;
int sampleCount = 10;
analogRead(APin);
analogRead(CPin);
for(int i = 0; i < sampleCount ; i++) {
AReading += analogRead(APin);
CReading += analogRead(CPin);
}
AReading = AReading / sampleCount;
CReading = CReading / sampleCount;
int CMSpeed = map(CReading, 0, 1023, 275, 375);
int AMPosit = map(AReading, 0, 1023, 1510, 1830);
servo.write(AMPosit);
motors.setM2Speed(CMSpeed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.