Working fine, but is it ok?
Not using millis().
Any input?
void defDI() { pinMode(MKR_BTN, INPUT_PULLUP); }
uint8_t buttonPoll()
{
static uint8_t mBTNout=0;
static uint8_t cy=0;
if (!digitalRead(MKR_BTN)) { if (cy>=20) { mBTNout=1; cy=0; } if (cy<=220) cy++; } else { mBTNout=0; cy=0; }
return mBTNout;
}
Complete code,
#define MKR_BTN A1 //BUTTON PIN.
String debugString = "";
void setup() {
// put your setup code here, to run once:
defDI();
debugStart();
}
void loop() {
// put your main code here, to run repeatedly:
uint8_t button = buttonPoll();
debugString = "BUTTON ";
if (button) debugString += "PRESSED";
if (!button) debugString += "NOT PRESSED";
debugPoll();
}
void defDI() { pinMode(MKR_BTN, INPUT_PULLUP); }
uint8_t buttonPoll()
{
static uint8_t mBTNout=0;
static uint8_t cy=0;
if (!digitalRead(MKR_BTN)) { if (cy>=20) { mBTNout=1; cy=0; } if (cy<=220) cy++; } else { mBTNout=0; cy=0; }
return mBTNout;
}
void debugStart() { SerialUSB.begin(9600); }
void debugPoll() {
if (SerialUSB) {
static uint32_t eee = 0;
const uint8_t interval = 2;
if (millis() - eee >= interval*200UL) { SerialUSB.print("\n >"); Serial.print(debugString); eee=millis(); }
}
if (SerialUSB.available())
{
uint8_t temp=0;
char c=SerialUSB.read();
switch (c)
{ //INPUT FUNCTIONS, FOR DEBUGGING.
case 'A':
SerialUSB.print("\nA:");
}
}
}