Go Down

Topic: smoothing algorithm and instant feedback (Read 978 times) previous topic - next topic

ilteris

Sep 16, 2006, 07:16 pm Last Edit: Sep 16, 2006, 07:17 pm by ilteris Reason: 1
Hello Arduino lovers,
I have built a circuit where I am getting values from a pre-amplified electrec mic and using those values to turn my gearhead motor in two directions. I am using a h-bridge to reverse the direction.  It is working ok, only my problem is it triggers kind of with delay of 1 second to 2 second than it should be.  I am assuming this could be because of the serial packets that I am sending. Here is my code and I really welcome your advices about the code.
Code: [Select]

int analogPin = 2; // analogIn
int analogValue = 0; // keep the value here

#define motor1Pin 13
#define motor2Pin 12
#define speedPin   9 // this is the pin that PVM from H-Bridge


void setup() {
 pinMode(motor1Pin, OUTPUT);
 pinMode(motor2Pin, OUTPUT);
 pinMode(speedPin, OUTPUT);
 digitalWrite(speedPin, HIGH);
 Serial.begin(9600);
}


void loop() {

 analogValue = analogRead(analogPin)/4; // scale down a little bit.
 if(analogValue > 200) { // if iserial value is over 200
   digitalWrite(motor1Pin, HIGH);
   digitalWrite(motor2Pin, LOW);
 }
 else if (analogValue <200) { // reverse
   digitalWrite(motor2Pin, HIGH);
   digitalWrite(motor1Pin, LOW);
 }

 //print in many formats:
 // print a tab
 Serial.print(analogValue);      // print the ASCII encoded decimal analogValue
 Serial.print('\t');                  // print a tab
 Serial.println();                    // print a linefeed and carriage return

   delay(10);
 }



Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy