Arduino and Sensors

Real time servo control

Spyridon Ampanavos
smoothServo.ino
/* Smoothly control a servo
*  
*  Control a servo using a potentiometer
*  This code removes potential noise in the readings
*  and makes the servo respond in smooth way to abrupt changes.
*  This can be useful to prevent fragile moving parts of your project
*  from breaking in some cases
*  
*/


#include <Servo.h>


Servo myservo;
float smoothPos = 0;


void setup() {
    myservo.attach(9);
}


void loop() {
    int pot = analogRead(A0);
    float pos = map(pot, 0, 1023, 0, 180);
    float smoothPos = 0.98*smooothPos + 0.02*pos;
}

Arduino Motor Shield Introduction

Aaron Laniosz
Adafruit_Motor_Shield_V2_Library.zip
EnableInterrupt.zip
RCPulseIn.zip

#include <Wire.h>
#include <Adafruit_MotorShield.h>

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
//Adafruit_DCMotor *myMotor = AFMS.getMotor(2);

void setup() {
     AFMS.begin();
}

void loop() {
     myMotor->setSpeed(255);
     myMotor->run(FORWARD);
     delay(1000);
}