Not getting anywhere on Adafruit. So, I'm going to continue here. I tried 2 Futaba servos and get the same response. The servo moves maybe an 8th of an inch. Almost like the servos is seized up. Pull it from the VCC and it moves freely. Connect VCC again, it seizes up.
So, my question is did I program it correctly to sweep the arm from Pos A to Pos B? Or did I just give it an output the same as the led?
/* Created by Nick Sebring: November 2017
This sketch is designed to activate a barcode reader by moving a chart in front of
the VCNL4010 I2C Proximity sensor. Thus triggering the servo to move a magnet over the sensor
in the handle of the barcode reader, activating the barcode readers infrared scanner. Thus avoiding
to reach across my desk and having to pull the trigger. How lazy can us humans be? Hahahaha
The SCL and SDA are connected to #0 & 2 of the 5V Trinket
Adding the refresh for the servo
*/
#include "Adafruit_SoftServo.h"
#include "Adafruit_VCNL4010.h"
#define SERVOPIN 4 // Servo control line (WHITE) on Trinket Pin #4
Adafruit_SoftServo tinyServo; //creates servo object
const int ledPin = 1;// LED on pin 1 to notify servo sketch is working
Adafruit_VCNL4010 vcnl;
void setup() {
// Set up the interrupt that will refresh the servo for us automagically
OCR0A = 0xAF; // any number is OK
TIMSK |= _BV(OCIE0A); // Turn on the compare interrupt (below!)
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);// Set led off at start-up
tinyServo.attach(SERVOPIN); // attaches the servo
//tinyServo.write(45);
//delay(15); // Wait 15ms for the servo to reach the position
if (! vcnl.begin()) {
while (1);
}
}
void loop() {
if (vcnl.readProximity() > 2150)//2125 seems to be ideal without plastic cover
{
tinyServo.write(25);
digitalWrite(ledPin, HIGH);
// delay(15); // waits 15ms for the servo to reach the position
}
else
{
tinyServo.write(160);
digitalWrite(ledPin, LOW);//
//delay(15); // waits 15ms for the servo to reach the position
}
}
// Suggested by Adafruit
// We'll take advantage of the built in millis() timer that goes off
// to keep track of time, and refresh the servo every 20 milliseconds
volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect) {
// this gets called every 2 milliseconds
counter += 2;
// every 20 milliseconds, refresh the servos!
if (counter >= 20) {
counter = 0;
tinyServo.refresh();
}
}
Thanks