Hi,
sorry, but I really can't name this topic. I'm trying to explain what happens with my sketch.
(Arduino nano, win10 x64, ARDUINO 1.8.1 )
I'm implementing menu on arduino controlled by several buttons. Variable ButtonPressed shows which button was pressed. ButtonHandler procedure does some depending on ButtonPressed.
Here is minimal part of my code:
js1Click.update(); //update bounce2 object - js1 is one of the buttons
Serial.println(js1Click.read()); //this outputs garbage to the serial port = "?b???????En?"
if (js1Click.fell()) { FellTime = millis(); }
if (js1Click.rose()) { //this is to detect long click
RoseTime = millis();
if (RoseTime - FellTime < btLongPressLatency) { ButtonPressed = btJs1Click; }
else { ButtonPressed = btJs1LongClick; }
}
if (ButtonPressed == 0) { //reset counters if nothing was pressed
btTimeNoPress = millis();
btWasChecked = false;
btRepeatTimePress = 0;
}
if (ButtonPressed) { //do what i need depending on what was pressed
// Serial.println(ButtonPressed);
if (!btWasChecked) {
ButtonHandler();
btWasChecked = true;
btRepeatTimePress = 0;
}
}
Compiler output
Compiling 'Rewinder_Peter' for 'Arduino Nano w/ ATmega328'
Program size: 14,240 bytes (used 46% of a 30,720 byte maximum) (1.39 secs)
Minimum Memory Usage: 630 bytes (31% of a 2048 byte maximum)
AVR Memory Usage
----------------
Device: atmega328p
Program: 14240 bytes (43.5% Full)
(.text + .data + .bootloader)
Data: 630 bytes (30.8% Full)
(.data + .bss + .noinit)
text data bss dec hex
0 14240 0 14240 37a0
If I remove
Serial.println(js1Click.read());
this part of sketch doesn't work at all. I.e js1Click.update(); doesn't work and ButtonPressed = 0
If I uncomment
Serial.println(ButtonPressed);
Serial.println(js1Click.read()) prints 1 instead of garbage (as button is really not pressed) and this part of sketch doesn't work as well.