From 200b7b2e6d4cf424ce07fd48ed08e5c95d4cb056 Mon Sep 17 00:00:00 2001 From: chiararuggeri Date: Tue, 13 Jun 2017 15:09:24 +0200 Subject: [PATCH] Fixed LEDs' inverted logic in analogWrite function --- cores/arduino/wiring_analog.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index cef30e3..8bf838b 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -146,13 +146,32 @@ uint32_t analogRead( uint32_t ulPin ){ void analogWrite(uint32_t ulPin, uint32_t ulValue) { uint16_t val; - if(writeResolution==8) + if(writeResolution==8){ +#if defined ARDUINO_NRF52_PRIMO_CORE + // if a LED is chosen reverse the value because of the LEDs' reverse logic + if(ulPin == 10 || ulPin == 11 || ulPin == 12 || ulPin == 13) + ulValue = 255 - ulValue; +#endif //ARDUINO_NRF52_PRIMO_CORE val=(uint16_t) (ulValue*10000/255); - else if(writeResolution==10) + } + + else if(writeResolution==10){ +#if defined ARDUINO_NRF52_PRIMO_CORE + // if a LED is chosen reverse the value because of the LEDs' reverse logic + if(ulPin == 10 || ulPin == 11 || ulPin == 12 || ulPin == 13) + ulValue = 1023 - ulValue; +#endif //ARDUINO_NRF52_PRIMO_CORE val=(uint16_t) (ulValue*10000/1024); - else //assuming 12 bit resolution + } + + else{ //assuming 12 bit resolution +#if defined ARDUINO_NRF52_PRIMO_CORE + // if a LED is chosen reverse the value because of the LEDs' reverse logic + if(ulPin == 10 || ulPin == 11 || ulPin == 12 || ulPin == 13) + ulValue = 4095 - ulValue; +#endif //ARDUINO_NRF52_PRIMO_CORE val=(uint16_t) (ulValue*10000/4096); - + } // This array cannot be allocated on stack (hence "static") and it must // be in RAM (hence no "const", though its content is not changed). static uint16_t /*const*/ seq_values[]={0};