MediaTek-Labs / Arduino-Add-On-for-LinkIt-SDK

Arduino board support package for LinkIt 7697
https://docs.labs.mediatek.com/resource/linkit7697-arduino/en
34 stars 33 forks source link

`analogWrite()` stops working after `pinMode()` is called #65

Closed pablosun closed 6 years ago

pablosun commented 6 years ago

The following example does not work on BSP v0.9.6:

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);    // remote this line and this example works.

}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second

  pinMode(LED_BUILTIN, OUTPUT);
  analogWrite(LED_BUILTIN, 255);   // turn the LED on (HIGH is the voltage level)
  delay(300);                       // wait for a second
  analogWrite(LED_BUILTIN, 0);    // turn the LED off by making the voltage LOW
  delay(300);                       // wait for a second
  analogWrite(LED_BUILTIN, 255);   // turn the LED on (HIGH is the voltage level)
  delay(300);                       // wait for a second
  analogWrite(LED_BUILTIN, 0);    // turn the LED off by making the voltage LOW
  delay(300);                       // wait for a second
}
pablosun commented 6 years ago

Note that, for Arduino Uno,

1) analogWrite() can be called after digitalWrite and pinMode 2) However, calling digitalWrite after analogWrites does not work. See https://forum.pjrc.com/threads/9-digitalWrite-doesn-t-work-after-analogWrite-on-the-same-pin 3) To call digitalWrite after analogWrite, pinMode must be called again to put the pin back to GPIO mode.

We'll follow the same behavior for LinkIt 7697.