I'm trying to use an existing Arduino library on the Raspberry Pi Pico. The library is here:
https://github.com/j-bellavance/EdgeDebounce/tree/master
It's based on some interesting insight at Jack Ganssel's blog: http://www.ganssle.com/debouncing.htm
The library works great on an ATMega 328, but I got two errors when changing to the Raspberry Pi Pico.
The first one was resolved by editing the last line of EdgeDebounce.h like this:
//#endif; // Arduino ATMega version
#endif // Pico version, also works on ATMega
The second is a bit more complex. Here's the relevant section of code, these are lines 78 - 102 in EdgeDebounce.cpp :
byte EdgeDebounce::debounce(byte pin) {
unsigned long pinStatus;
do {
pinStatus = 0xffffffff;
for (byte i = 1; i <= MYsensitivity; i++) pinStatus = (pinStatus << 1) | digitalRead(pin);
} while ((pinStatus != debounceDontCare) && (pinStatus != 0xffffffff));
return byte(pinStatus & 0x00000001);
}//debounce------------------------------------------------------------------------------------------------
//updateStatus===================================================================
//After releasing EdgeDebounceLite, I realized that EdgeDebounce could do more
//With this small piece of code, EdgeDebounce can return if a switch is
// .isclosed(); //Conducting current
// .isopen(); //Not conducting current
// .rose(); //Just went from open to closed
// .fell(); //just went from closed to open
//-------------------------------------------------------------------------------
void EdgeDebounce::update() {
byte newStatus = debounce();
if (MYmode == PULLUP) newStatus = !newStatus;
if (MYstatus == OPEN && newStatus == CLOSED) MYrose = true;
else MYrose = false;
if (MYstatus == CLOSED && newStatus == OPEN) MYfell = true;
else MYfell = false;
MYstatus = newStatus;
}//update-------------------------------------------------------------------------
When I try to compile, I get this error:
c:\Users\thisuser\Documents\Arduino\libraries\EdgeDebounce\EdgeDebounce.cpp: In member function 'void EdgeDebounce::update()':
c:\Users\thisuser\Documents\Arduino\libraries\EdgeDebounce\EdgeDebounce.cpp:102:14: error: invalid conversion from 'byte' {aka 'unsigned char'} to 'pinStatus' [-fpermissive]
102 | MYstatus = newStatus;
| ^~~~~~~~~
| |
| byte {aka unsigned char}
exit status 1
Compilation error: exit status 1
So I see that the byte of "newStatus" doesn't convert to "pinStatus" which is an unsigned long. I've done a bunch of Google searches but can't quite figure out what the fix is.
pinStatusdeclared? Not insideEdgeDebounce::debounce- that's a local declaration. – Nick Gammon Jul 13 '23 at 07:27