Skip to content

Instantly share code, notes, and snippets.

@raster
Created May 17, 2015 16:08
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 raster/9a18e6a9765b8e9f4bef to your computer and use it in GitHub Desktop.
Save raster/9a18e6a9765b8e9f4bef to your computer and use it in GitHub Desktop.
/*
* 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