Pages: [1]   Go Down
Author Topic: smoothing algorithm and instant feedback  (Read 836 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
  }


« Last Edit: September 16, 2006, 12:17:54 pm by ilteris » Logged

Pages: [1]   Go Up
Jump to: