You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to call digitalWrite (or maybe another new method) to say:
I don't care of the desired value, just read the current value and flip (invert) it.
AFAIK digitalRead can't be really used, as we speak about output pin, and in any case it will waste time for nothing.
Anyhow, the goal should be pretty much easy with the current code, as digitalWrite call WriteRegisterPin, which already read the port status and do bitwise operation.
In detail,
Currently, the WriteRegisterPin method take in input level to decide how to change the bit for the port, read, change and write the port back.
if (level == 2) { // this is just a sample, likely a switch/case would be more appropriate
// ^= -> XOR bitwise
// << -> left shift
CSDataArray[0] ^= ~(1 << regpin);
}
Would the feature make sense in CS library?
Do you think that a new function would be preferable, like flipDigitalWrite, or just having a new value passed to digitalWrite?
would make sense to check in WriteRegisterPin (or in digitalWrite or...) the value passed? And if so, how to properly report back to the user that garbage has been passed?
Thank you very much,
Daniele
The text was updated successfully, but these errors were encountered:
I need to call digitalWrite (or maybe another new method) to say:
I don't care of the desired value, just read the current value and flip (invert) it.
AFAIK digitalRead can't be really used, as we speak about output pin, and in any case it will waste time for nothing.
Anyhow, the goal should be pretty much easy with the current code, as digitalWrite call WriteRegisterPin, which already read the port status and do bitwise operation.
In detail,
Currently, the WriteRegisterPin method take in input
level
to decide how to change the bit for the port, read, change and write the port back.Seems to me that is possible to pass
level
with anyint
value, only 0 will have a different behavior than others.level is taken, in example, from CS.digitalWrite without checking the value as well (AFAIK Arduino digitalWrite do the same just with uint8_t in place of int: https://github.com/arduino/ArduinoCore-avr/blob/9f8d27f09f3bbd1da1374b5549a82bda55d45d44/cores/arduino/wiring_digital.c#L156 ).
Eg i can set "6" as value, and it will be considered != 0.
Here the snippet
Centipede/Centipede.cpp
Lines 85 to 98 in 11bda08
So my idea is to
So as logic it could be like:
flipDigitalWrite
, or just having a new value passed to digitalWrite?Thank you very much,
Daniele
The text was updated successfully, but these errors were encountered: