Hello,
I have arduino uno board with attached funshield and I would like to use the avr-debugger with it. Unfortunately, it does not seem to work.
When I hit debug, the debugger starts loading but then ends and nothing happens. I dont see my variables, nothing. Just a blank screen here:
I have tried both calling breakpoint(); manually and using the red dot. Nothing worked.
For reference, I am adding my source code file and my platformio.ini file.
Any help would be appreciated.
Souce Code:
#include <Arduino.h>
#include <funshield.h>
#include "avr8-stub.h"
constexpr int LEDs[] = {led4_pin, led3_pin, led2_pin, led1_pin};
constexpr int LEDsCount = sizeof(LEDs) / sizeof(LEDs[1]);
constexpr int moduloVal = 16;
int value = 0;
class Button {
private:
enum class State {
RELEASED,
PRESSED
};
int pin;
State currentState;
State formerState;
unsigned long lastTimePressed; // last time the button was physically pressed
unsigned long nextRepeatTime;
static constexpr int holdingDetectDelay = 1000;
static constexpr int holdingDelay = 300;
public:
Button(int pin) {
this->pin = pin;
}
void initialize() {
pinMode(pin, INPUT);
}
void updateStatus() {
unsigned long currentTime = millis();
bool state = !digitalRead(pin);
formerState = currentState;
currentState = state ? State::PRESSED : State::RELEASED;
if (currentState == State::PRESSED && formerState == State::RELEASED) {
lastTimePressed = currentTime;
nextRepeatTime = lastTimePressed + holdingDetectDelay;
}
}
bool wasPressed() {
return (currentState == State::PRESSED) && (formerState == State::RELEASED);
}
bool wasLongPressed() {
unsigned long currentTime = millis();
if (currentState == State::RELEASED) {
return false;
}
if (currentTime >= nextRepeatTime) {
nextRepeatTime += holdingDelay;
return true;
}
return false;
}
bool wasLongerPressed() {
unsigned long currentTime = millis();
return wasLongPressed() && currentTime - lastTimePressed > 4000;
}
bool isHeld(unsigned long currentTime) {
return (currentState == State::PRESSED) && (currentTime - lastTimePressed > holdingDetectDelay);
}
};
Button increaseButton(button1_pin);
Button decreaseButton(button2_pin);
void binaryLight (int input) {
for (int i = 0; i < LEDsCount; i++) {
auto isEven = input % 2 == 1;
digitalWrite(LEDs[i], isEven ? ON : OFF);
input = input / 2;
}
}
void changeValue(int valueToAdd) {
value += valueToAdd;
binaryLight(value % moduloVal);
}
void setup() {
for (int i = 0; i < LEDsCount; i++) {
pinMode(LEDs[i], OUTPUT);
}
debug_init();
increaseButton.initialize();
decreaseButton.initialize();
}
void loop() {
breakpoint();
increaseButton.updateStatus();
decreaseButton.updateStatus();
if (increaseButton.wasPressed() || increaseButton.wasLongPressed()) {
changeValue(1);
}
if (decreaseButton.wasPressed() || decreaseButton.wasLongPressed()) {
changeValue(15);
}
}
and ini file:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps = jdolinay/avr-debugger@^1.5
debug_tool = avr-stub
debug_port = ttyACM0