Circular LED with Arduino using digitalRead() stops half the LEDs from working

I am using the Grove Circular LED on the Arduino platform. I can address all LED ok until my code contains the digitalRead() function. When this function is used only half of the LED’s work. I have managed to track down the issue to be with the turnoffpwm() function within the digitalRead(). If I comment out the contents of the turnoffpwm() function i.e. an empty function, everything is o.k.

Anybody got any ideas what the problem might be and how to fix it ?

Below are the software and documentation for this product.I hope it helped you.


https://wiki.seeedstudio.com/Grove-Circular_LED/#software_1

Hello, I have read this documentation many times hoping to find the answer. The problem with using digitalRead() even breaks the example code within the library.

I have the following code, which turns on each led 1 to 24 every second.
This code will only turn on 12 of the leds’. However if digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN)); is removed and replaced by
toggle = ~toggle;
digitalWrite(LED_BUILTIN, (toggle & 0x01));
All 24 leds will illuminate in turn and the Builtin LED will toogle every second.

I have tried reading a different port i.e. digitalRead(3), this also breaks the code.

// definitions and variables.
Grove_LED_Bar bar(6, 7, 0, LED_CIRCULAR_24);
uint32_t CLedPosition = 1 ;
uint32_t LastUpdate ;
uint8_t toggle = 0 ;

// this code is in the void loop ()
if (millis()-LastUpdate >= 1000){
//digitalWrite(LED_BUILTIN,HIGH);
//digitalWrite(LED_BUILTIN,LOW);
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));

  CLedPosition <<= 1;  // shift one bit
  if (CLedPosition >= 0x1000000){
    CLedPosition=1;
  }
  bar.setBits(CLedPosition);

// toggle = ~toggle;
// digitalWrite(LED_BUILTIN, (toggle & 0x01));

  LastUpdate=millis();
}

Can you send us a PR?

what is the best way to do this ?

hello, are you still able to help with the issue i am having ?

Hi @andykennerley, You already solved the issues right?

issue is not solved. I have found the function that appears to be causing the problem, but i don’t understand why. I was hoping you might be able to help. (with the turnoffpwm() commented out, the digitalRead() now doesn’t always return the correct value.) i guess the turnoffpwm() has been implemented for a reason.