55
66// Servo stuff
77Servo myservo;
8- #define SERVO_MOUTH_OPEN 0
9- #define SERVO_MOUTH_CLOSED 180
10- #define SERVO_PIN 3
8+ #define SERVO_MOUTH_OPEN 750 // Servo pulse microseconds
9+ #define SERVO_MOUTH_CLOSED 1850
10+ #define SERVO_PIN 3
1111
12- #define BUTTON_PIN 2
12+ #define BUTTON_PIN 2
1313
1414// WAV player stuff
1515#define WAV_BUFFER_SIZE 256
@@ -66,7 +66,7 @@ void user_loop(void) {
6666 uint32_t elapsed = millis() - wavEventTime; // Time since audio start
6767 uint16_t frac = elapsed % 500; // 0 to 499 = 0.5 sec
6868 float n = 1.0 - ((float)abs(250 - frac) / 500.0); // Ramp 0.5, 1.0, 0.5 in 0.5 sec
69- myservo.write ((int)((float)SERVO_MOUTH_CLOSED + (float)(SERVO_MOUTH_OPEN - SERVO_MOUTH_CLOSED) * n));
69+ myservo.writeMicroseconds ((int)((float)SERVO_MOUTH_CLOSED + (float)(SERVO_MOUTH_OPEN - SERVO_MOUTH_CLOSED) * n));
7070 // BUTTON_PIN button is ignored while sound is playing.
7171 } else if(wavListPtr) {
7272 // Not currently playing WAV. Check for button press on pin BUTTON_PIN.
@@ -79,7 +79,7 @@ void user_loop(void) {
7979 }
8080 pinMode(BUTTON_PIN, INPUT);
8181 if(myservo.attached()) { // If servo still active (from recent WAV playing)
82- myservo.write (SERVO_MOUTH_CLOSED); // Make sure it's in closed position
82+ myservo.writeMicroseconds (SERVO_MOUTH_CLOSED); // Make sure it's in closed position
8383 // If it's been more than 1 sec since audio stopped,
8484 // deactivate the servo to reduce power, heat & noise.
8585 if((millis() - wavEventTime) > 1000) {
0 commit comments