Rabu, 16 April 2014

ARDUINO - ESC PWM Control Example

int escPin = 9;
int arm = 1000;
int arma = 1150;
int arm1 = 1160;
int arm2 = 1170;
int speedvalue = 1180;

void setup()
 {
   Serial.begin(9600); 
// PROSES ARMING **********************************************
   pinMode(escPin, OUTPUT);
   for (int count = 0; count < 50; count++)
   {
     digitalWrite(escPin, HIGH);
     delayMicroseconds(arm);
     digitalWrite(escPin, LOW);
     delay(20);
   }
   for (int counta = 0; counta < 70; counta ++)
   {
     digitalWrite(escPin, HIGH);
     delayMicroseconds(arma);
     digitalWrite(escPin, LOW);
     delay(20);
   }
 }

void loop()
{
  if(Serial.available()>0)
  {
    int dataditerima=Serial.read();
    if(dataditerima=='1')
    {
      for (int count1 = 0; count1 < 10; count1++)
      {
        digitalWrite(escPin, HIGH);
        delayMicroseconds(arm1);
        digitalWrite(escPin, LOW);
        delay(20);
      }
    }
    if(dataditerima=='2')
    {
      for (int count2 = 0; count2 < 20; count2++)
      {
        digitalWrite(escPin, HIGH);
        delayMicroseconds(arm2);
        digitalWrite(escPin, LOW);
        delay(20);
      }
    }
    if(dataditerima=='3')
    {
      for (int count2 = 0; count2 < 300; count2++)
      {
        digitalWrite(escPin, HIGH);
        delayMicroseconds(speedvalue);
        digitalWrite(escPin, LOW);
        delay(20);
      }
    }
    else
    {
      digitalWrite(escPin, LOW);
    }
  }
}

Tidak ada komentar:

Posting Komentar