Sitat av
Ferner-Jensen
Dette blir også feil, siden PWM-signalet ikke er separert med 20 ms.
Det går heller ikke ann å bruke to void loop() i samme program.
Jeg ville gjort noe slikt, en enkel if-test som benytter millis() for å sjekke tiden:
Kode
// This sketch arms the Platinum ESC
int escPin = 9;
int arm = 1000; // pulse width in microseconds for arming
int startupvalue = 1300; //pulse width in microseconds for startup
int startuptime = 5000; //5000 ms delay for startup
int speedvalue = 1900; // pulse width in microseconds for operation
void setup()
{
// It appears that the ESC will accept a range of values for the arming
// sequence. This provides 10 pulses with a pulse width of 1000 us with
// with a 20 ms delay between pulses.
pinMode(escPin, OUTPUT);
for (int count = 0; count < 150; count++) {
digitalWrite(escPin, HIGH);
delayMicroseconds(arm);
digitalWrite(escPin, LOW);
delay(20);
}
}
void loop()
{
// Once armed the ESC needs to receive a pulse train to operate the
// the motor. The motor speed is controlled by the duration of the
// pulse width.
// This simple loop provides a pulses width a width of 1350 us and a
// separation of 20 ms.
// Startup in the first 5000 ms
if (millis() < startuptime) {
digitalWrite(escPin, HIGH);
delayMicroseconds(startupvalue);
digitalWrite(escPin, LOW);
delay(20);
}
//Normal operation below
else {
digitalWrite(escPin, HIGH);
delayMicroseconds(speedvalue);
digitalWrite(escPin, LOW);
delay(20);
}
}
Takk!
Den fungerer fint, men ser det at etter 5 sek med startupvalue1300 ( 30 % ) så blir det for brått og øke til 100%. Skulle gjerne hatt at den da hadde en rolig akslasjon på 10 sek. Så 30% i 5 sek, så 30-->100% på 10 sek.