Skip to content

Instantly share code, notes, and snippets.

@danesparza
Created October 13, 2020 19:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danesparza/5e5cc6419e2f14908db6f15b5576f6b4 to your computer and use it in GitHub Desktop.
Save danesparza/5e5cc6419e2f14908db6f15b5576f6b4 to your computer and use it in GitHub Desktop.
Updated jawduino code to control a servo based on sound
#include <Servo.h> // Standard servo library
Servo myservo;
#define SERVO_PIN 9 // Set to the controller pin for the servo
int servo_pos = 0;
int val1; // Floating value 1
int val2; // Floating value 2
int val3; // Floating value 3
char smon[30]; // Serial monitor buffer
void setup() {
myservo.attach(SERVO_PIN);
Serial.begin(9600);
}
void loop() {
// Set our initial servo position:
servo_pos = 0;
// Read our (floating) LED values
val1 = analogRead(A1);
val2 = analogRead(A2);
val3 = analogRead(A3);
if(val1 < 341) servo_pos += 60;
if(val2 < 341) servo_pos += 60;
if(val3 < 341) servo_pos += 60;
// Debugging: Use the arduino IDE serial monitor to see these values
sprintf(smon, "A1:%4d A2:%4d A3:%4d Pos:%4d", val1, val2, val3, servo_pos);
Serial.println(smon);
// Set the servo position:
// val1 = map(val1, 0, 1023, 0, 180);
myservo.write(servo_pos);
// Tiny delay:
delay(15);
}
@danesparza
Copy link
Author

Use the same audio processing chip mentioned here: http://buttonbanger.com/downloads/jawduino/jawduino.pdf along with the same solder points (see 'where to solder' and picture)

@danesparza
Copy link
Author

One thing I still don't understand is the magic numbers used in these lines

@wwebber46
Copy link

having trouble with map function

@wwebber46
Copy link

pop

@danesparza
Copy link
Author

What's the problem you're having with the map function? (It's currently commented out)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment