M4_Eyes: add fizzgig WAVs, change servo writes to microsec

This commit is contained in:
Phillip Burgess 2019-10-07 13:39:21 -07:00
parent 80fef819a4
commit ca71dcaebf
4 changed files with 6 additions and 6 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

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