Created
October 13, 2020 19:02
-
-
Save danesparza/5e5cc6419e2f14908db6f15b5576f6b4 to your computer and use it in GitHub Desktop.
Updated jawduino code to control a servo based on sound
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
One thing I still don't understand is the magic numbers used in these lines
having trouble with map function
pop
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
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)