I am trying to control a servo with with two 555 timer hooked up to an infrared emitter. I was able to control a shift register using this method but for some reason I when I try and use a servo all it does is shakes a little and doesnt turn. Here is my code:
volatile long lasttime = 0;
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 10;
////Pin connected to DS of 74HC595
int dataPin = 9;
#include <Servo.h>
Servo myservo; //create servo object to control a servo
int val; //variable to read the value from the analog pin
void setup()
{
// Go with faster than normal serial speed
Serial.begin(115200);
// Set Interrupt 0 (which is on digital pin 2) to call 'onTick'
// when the signal rises.
pinMode(2, INPUT);
attachInterrupt( 0, onTick, RISING );
myservo.attach(11); //attach the servo on pin 11 to the servo object
}
void loop()
{
// Note that we're doing anything in the main loop,
// everything happens in onTick
}
void onTick()
{
// print out how many milliseconds occurred between the last
// clock tick and this one.
long thistime=millis();
long time=thistime-lasttime;
Serial.println(time);
val = map(time, 0, 120, 0, 179); //scale it to use with servo
myservo.write(val);
delay(15);
lasttime = thistime;
}