KA2284 LED sound meter code

I am trying to do a talking skull project using the Uno R3 with a KA2284 sound meter that I saw on YouTube for a Jawduino from Buttonmasher.com. The code I am trying to use that moves the servo according to sound level is not working. It is saying 'audio value' was no declared. Not sure if I am missing a whole section of code, but this is the code I am using:

void audio_updates()
{
    audio_value = 0
    if(analogRead(A0) <341)  + = 60;
    if(analogRead(A1) <341)  + = 60;
    if(analogRead(A2) <341)  + = 60;
  // put your setup code here, to run once:
void set_minimax()
{
    servo.setMinimumPulse(map 92,0,180,512,2400));
    servo.setMaximumPulse(map 92,0,180,512,2400));

I still need to add what pmw to use, like 3. Any help with this is appreciated.

Yes you have no setup function and no loop function. What you posted will not compile.
You have no libraries installed or indeed anything that makes sense.

This makes no sense at all.

What is it doing. I assume some sort of variable is having 60 added to it, but you have missed the variable name, in all four lines.

Why are you doing this anyway?
Please read getting the best out of this forum to find out how to ask a question.

You need to post all your code along with a schematic, hand drawn is fine Fritzing is not.
You need to post a link to the thing you say you have, the KA2284 the link you posted to button masher just times out.

I’m trying to get the servo to move at to different positions based on volume of audio. I copied the code a person was using to make it do it for them. I have the audio meter library downloaded but didn’t include it in the code, which I realized why the servo had no idea what to do. I’ll keep looking for more libraries in case I don’t have the correct one and the forum to how to use an audio meter with the arduino.

OK I thought you wanted help but it looks like I was wrong, because you don't want to cooperate and cooperation is the only way anyone can help you.

In case you didn't get that link here it is:-
how to get the best out of this forum

This is the code for the jawduino project. You will also need to get the library SoftRCPulseOut.h

/***********************************************************
08-14-2016 Mike North This is a little proof of concept 
to make a servo move in sync with audio.
*******************/
#include "SoftRcPulseOut.h"
#define TEST_PIN 11 //pin 11 set to ground will kick off the servo sweep test
int audio_value = 0;
long lastMsg = 0;
long sleepWindow = 300000; //if 5 minutes go by with no signal, then put the servos to bed
SoftRcPulseOut servo;
volatile boolean servosEnabled = false;
volatile boolean ledsOn = true;
volatile unsigned long currentTime = 0;
volatile unsigned long lastLEDtime = 0;
unsigned long resetWait = 120000; //servos sleep if not changed within this time frame (120 secs)

void setup()
{
	set_minmax();
	pinMode(TEST_PIN,INPUT);  //pin 11 will be 
	digitalWrite(TEST_PIN,HIGH); //assign pull-up resistor
} 

void loop()
{
  servo_test();
  audio_updates(); //read sample from audio input and apply average to buffer
  if(servosEnabled) 
  {
	action(); //servos are handled in the action loop
	SoftRcPulseOut::refresh();
	if((millis() - lastMsg) > sleepWindow)
	  detach_servos();
  }
} 
void attach_servos()
{   // attach the pin to the servo object
    servo.attach(2);
    servosEnabled = true;
}
void detach_servos()
{   // detach the servo objects
    servo.detach();
    servosEnabled = false;
}
void servo_test()
{
	if(digitalRead(TEST_PIN) == HIGH) return;
	attach_servos();
	SoftRcPulseOut::refresh();
	for(int i = 0; i < 360;i++)
	{
		if(i < 180)
			audio_value = i;
		else
			audio_value = 359 - i;
		action();
		for(int i = 0; i < 10; i++)
		{
		   delay(1); 
		   SoftRcPulseOut::refresh();
		}
	}
	detach_servos();
}
void audio_updates()
{
	audio_value = 0;
	if(analogRead(A0) < 341) audio_value += 50;
	if(analogRead(A1) < 341) audio_value += 50;
	if(analogRead(A2) < 341) audio_value += 50;

	if(audio_value > 0) 
	{
		lastMsg = millis(); //save the time stamp from when we last had some action
		if(!servosEnabled)attach_servos();
	}
}
void action() { 
  if (!servosEnabled) attach_servos();
  servo.write(audio_value);
  SoftRcPulseOut::refresh();
} 
void set_minmax()
{
	//set the first parameter in the following functions to a number between 0 and 180.
	//I used 92 and 72 in my tests to give about 20 degrees of motion.
	//You may swap the large and small numbers to reverse direction.
	//Just play with them, upload the code, then ground pin 11 to run the sweep test.
	// Be sure to only play with these numbers while the jaw linkage is disconnected,
	//  otherwise, you risk hitting mechanical limits and damaging your linkage or servo!
	servo.setMinimumPulse(map(62,0,180,512,2400));
	servo.setMaximumPulse(map(120,0,180,512,2400));

Sometimes it might be best to help someone rather than try to drive them off the board.

Thank you for the code! I appreciate the help you provided. I will get the right library installed as you mentioned. Thanks again for the code I was looking for.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.