Hi I'm using AS7 with VM 1909.27.0 and Arduino 1.8.5
I want to use the Ace Button library (
https://github.com/bxparks/AceButton) and am currently playing with the examples.
I have opened the ArrayButtons.ino example. It compiles and works fine in Arduino, but throws following errors in VM:
Error compiling project sources
ArrayButtons.ino: 17:18: error: variable or field 'handleEvent' declared void
Debug build failed for project 'ArrayButtons'
ArrayButtons.ino: 17:18: error: 'AceButton' was not declared in this scope
ArrayButtons.ino:17: note suggested alternative
AceButton.h:38: In file included from
ArrayButtons.ino:11: from
AceButton.h:50: note ace_button AceButton
class AceButton {
ArrayButtons.ino: 17:29: error: 'button' was not declared in this scope
ArrayButtons.ino: 17:45: error: expected primary-expression before 'eventType
ArrayButtons.ino: 17:64: error: expected primary-expression before 'buttonState
Error is thrown by the event handle. If I remove the event handle and its prototype (and lines referencing it) the source code compiles.
I have seen similar posts that required the prototype adding at the top of the code. However the prototype is clearly present in this case.
Is it a parsing order difference between Arduino and VM? Any way to fix?
Here's the code:
#include <AceButton.h>
using namespace ace_button;
const int LED_ON = HIGH;
const int LED_OFF = LOW;
const uint8_t NUM_LEDS = 6;
struct Info {
const uint8_t buttonPin;
const uint8_t ledPin;
bool ledState;
};
Info INFOS[NUM_LEDS] = {
{2, 8, LED_OFF},
{3, 9, LED_OFF},
{4, 10, LED_OFF},
{5, 11, LED_OFF},
{6, 12, LED_OFF},
{7, 13, LED_OFF},
};
AceButton buttons[NUM_LEDS];
void handleEvent(AceButton*, uint8_t, uint8_t);
void setup() {
delay(1000);
Serial.begin(115200);
while (! Serial);
Serial.println(F("setup(): begin"));
for (uint8_t i = 0; i < NUM_LEDS; i++) {
pinMode(INFOS[i].ledPin, OUTPUT);
pinMode(INFOS[i].buttonPin, INPUT_PULLUP);
buttons[i].init(INFOS[i].buttonPin, HIGH, i);
}
ButtonConfig* buttonConfig = ButtonConfig::getSystemButtonConfig();
buttonConfig->setEventHandler(handleEvent);
buttonConfig->setFeature(ButtonConfig::kFeatureClick);
buttonConfig->setFeature(ButtonConfig::kFeatureDoubleClick);
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
buttonConfig->setFeature(ButtonConfig::kFeatureRepeatPress);
Serial.println(F("setup(): ready"));
}
void loop() {
for (uint8_t i = 0; i < NUM_LEDS; i++) {
buttons[i].check();
}
}
void handleEvent(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.print(F("handleEvent(): eventType: "));
Serial.print(eventType);
Serial.print(F("; buttonState: "));
Serial.println(buttonState);
uint8_t id = button->getId();
uint8_t ledPin = INFOS[id].ledPin;
switch (eventType) {
case AceButton::kEventPressed:
digitalWrite(ledPin, LED_ON);
INFOS[id].ledState = LED_ON;
break;
case AceButton::kEventReleased:
digitalWrite(ledPin, LED_OFF);
INFOS[id].ledState = LED_OFF;
break;
}
}