Hi!
I was wondering if any of you could help me out with a problem I'm currently facing. I wrote a little sketch for my arduino that maps values I get from a LDR to a servo. On my Arduino it works like a charm:
#include <SoftwareServo.h>
SoftwareServo myservo; // create servo object to control a servo
int ldrpin = 0; // analog pin used to connect the LDR
int val; // variable to read the value from the analog pin
void setup()
{
Serial.begin(9600);
myservo.attach(A2); // attaches the servo on pin 2 to the servo object
}
void loop()
{
val = analogRead(ldrpin); // reads the value of the LDR (value between 0 and 1023)
Serial.println(val);
val = map(val, 0, 1023, 40, 130); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
SoftwareServo::refresh();
Serial.println(val);
}
Since it's really simple I thought I could port it to my digispark. But I just can't get it to work. I tries SimpleServo.h, SoftwareServo.h, Servo8Bit.h and even SoftRcPulseOut. I tries different servos as well. But i just get jitter or nothing at all.
Any suggestions?
I would be really glad if someone had an idea!
Thank you in advance.