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 ?
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.
// 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);
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.