An error occurred, and I was unable to compile the code.
In file included from /Users/admin/Desktop/ProffieOS/ProffieOS.ino:667:
/Users/admin/Desktop/ProffieOS/config/my_config.h:58:45: error: expected class-name before ‘{’ token
58 | struct AnalogReadHelper : public AnalogRead {
| ^
/Users/admin/Desktop/ProffieOS/config/my_config.h:60:9: error: ‘void AnalogReadHelper::Setup()’ marked ‘override’, but does not override
60 | void Setup() override {
| ^~~~~
/Users/admin/Desktop/ProffieOS/config/my_config.h:65:9: error: ‘void AnalogReadHelper::loop()’ marked ‘override’, but does not override
65 | void loop() override {
| ^~~~
/Users/admin/Desktop/ProffieOS/config/my_config.h: In constructor ‘AnalogReadHelper::AnalogReadHelper(int)’:
/Users/admin/Desktop/ProffieOS/config/my_config.h:59:41: error: class ‘AnalogReadHelper’ does not have any field named ‘AnalogRead’
59 | explicit AnalogReadHelper(int pin) : AnalogRead(pin) {}
| ^~~~~~~~~~
/Users/admin/Desktop/ProffieOS/config/my_config.h: In member function ‘void AnalogReadHelper::Setup()’:
/Users/admin/Desktop/ProffieOS/config/my_config.h:61:7: error: ‘value_’ was not declared in this scope
61 | value_ = -1;
| ^~~~~~
/Users/admin/Desktop/ProffieOS/config/my_config.h:62:7: error: ‘AnalogRead’ has not been declared
62 | AnalogRead::Setup();
| ^~~~~~~~~~
/Users/admin/Desktop/ProffieOS/config/my_config.h:63:7: error: ‘Start’ was not declared in this scope; did you mean ‘Star’?
63 | Start();
| ^~~~~
| Star
/Users/admin/Desktop/ProffieOS/config/my_config.h: In member function ‘void AnalogReadHelper::loop()’:
/Users/admin/Desktop/ProffieOS/config/my_config.h:66:11: error: ‘Done’ was not declared in this scope; did you mean ‘tone’?
66 | if (Done()) Start();
| ^~~~
| tone
/Users/admin/Desktop/ProffieOS/config/my_config.h:66:19: error: ‘Start’ was not declared in this scope; did you mean ‘Star’?
66 | if (Done()) Start();
| ^~~~~
| Star
/Users/admin/Desktop/ProffieOS/config/my_config.h:67:7: error: ‘AnalogRead’ has not been declared
67 | AnalogRead::loop();
| ^~~~~~~~~~
/Users/admin/Desktop/ProffieOS/config/my_config.h: In member function ‘virtual void BladeExtender::Loop()’:
/Users/admin/Desktop/ProffieOS/config/my_config.h:105:41: error: ‘struct AnalogReadHelper’ has no member named ‘value’
105 | value=retractReader.value();
| ^~~~~
/Users/admin/Desktop/ProffieOS/config/my_config.h:120:41: error: ‘struct AnalogReadHelper’ has no member named ‘value’
120 | value=retractReader.value();
| ^~~~~
/Users/admin/Desktop/ProffieOS/config/my_config.h:137:33: error: ‘struct AnalogReadHelper’ has no member named ‘value’
137 | value=retractReader.value();
| ^~~~~
/Users/admin/Desktop/ProffieOS/config/my_config.h:161:33: error: ‘struct AnalogReadHelper’ has no member named ‘value’
161 | value=retractReader.value();
| ^~~~~
exit status 1
Compilation error: expected class-name before ‘{’ token
#ifdef CONFIG_PRESETS
struct AnalogReadHelper : public AnalogRead {
explicit AnalogReadHelper(int pin) : AnalogRead(pin) {}
void Setup() override {
value\_ = -1;
AnalogRead::Setup();
Start();
}
void loop() override {
if (Done()) Start();
AnalogRead::loop();
}
};
AnalogReadHelper extendReader(blade4Pin);
AnalogReadHelper retractReader(10);
class BladeExtender : public Looper {
public:
const int extendSensorPin = blade4Pin;
const int retractSensorPin = 10;
const int motorAPin = rxPin;
const int motorBPin = txPin;
const int extendLimit = 1000;
const int retractLimit = 1005;
const char\* name() override { return "BladeExtender"; }
void Setup() override {
pinMode(extendSensorPin, INPUT);
pinMode(retractSensorPin, INPUT);
pinMode(motorAPin, OUTPUT);
pinMode(motorBPin, OUTPUT);
}
void Loop() override {
if (on\_ != SaberBase::IsOn()) {
on\_ = SaberBase::IsOn();
EnableBooster();
if (on\_) {
value=extendReader.value();
if ( value <= extendLimit) {
Serial.print("######Change extending\_####### ");
Serial.println(value);
extending\_ = true;
retracting\_ = false;
digitalWrite(motorAPin, HIGH);
digitalWrite(motorBPin, LOW);
start_time_millis\_= millis() + 3600;
} else {
Serial.println("######LOW####### ");
}
} else {
value=retractReader.value();
if (value <= retractLimit) {
Serial.print("######Change retracting\_####### ");
Serial.println(value);
retracting\_ = true;
extending\_ = false;
digitalWrite(motorAPin, LOW);
digitalWrite(motorBPin, HIGH);
start_time_millis\_= millis()+ 3600;
} else {
Serial.println("######LOW####### ");
}
}
}
if (extending\_) {
value= extendReader.value();
Serial.println(value);
if ((millis() > start_time_millis\_) || (value > extendLimit)) {
Serial.print("#####Hit the Brakes##### ");
Serial.println(value);
digitalWrite(motorAPin, HIGH);
digitalWrite(motorBPin, HIGH);
delayMicroseconds(50);
digitalWrite(motorAPin, LOW);
digitalWrite(motorBPin, LOW);
extending\_ = false;
retracting\_ = false;
} else {
//Serial.println("#####Do Nothing##### ");
}
} else if (retracting\_) {
value=retractReader.value();
Serial.println(value);
if ((millis() > start_time_millis\_) || (value > retractLimit)) {
//正常数値で止まったか確認
Serial.print("#####Hit the Brakes##### ");
Serial.println(value);
digitalWrite(motorAPin, HIGH);
digitalWrite(motorBPin, HIGH);
delayMicroseconds(50);
digitalWrite(motorAPin, LOW);
digitalWrite(motorBPin, LOW);
extending\_ = false;
retracting\_ = false;
} else {
//Serial.println("#####Do Nothing##### ");
}
}
}
private:
bool on\_ = false;
bool extending\_ = false;
bool retracting\_ = false;
int value;
uint32_t start_time_millis\_;
};
BladeExtender blade_extender;
Please paste better.
(click the “A”, switch to markdown, type three backticks(`) followed by cpp, press enter, paste, then type three more backticks (on a line by itself.)
You can use the “raw post” link to see what it should look like.
Anywyas, the problem is that I wrote “AnalogRead” instead of “AnalogReader”.
(That should at least fix one of the errors…)
I’m really sorry for not knowing the rules for pasting code.
I’m not very familiar with object-oriented programming, and I don’t have the ability to fix the code on my own. On top of that, I’m not very good at English either…
What is the correct way to write this?
No worries, we’ll make do. 
If you replace AnalogRead with AnalogReader, do you still get an error? If so, what?
“blade4pin” has been corrected to “blade4Pin.”
Is this correct?
struct AnalogReadHelper : public AnalogReader {
explicit AnalogReadHelper(int pin) : AnalogReader(pin) {}
void Setup() override {
value_ = -1;
AnalogReader::Setup();
Start();
}
void loop() override {
if (Done()) Start();
AnalogReader::loop();
}
};
AnalogReadHelper extendReader(blade4Pin);
AnalogReadHelper retractReader(10);
It still wouldn’t compile.
Compilation error: ‘void AnalogReadHelper::Setup()’ marked ‘override’, but does not override
I made a few adjustments here and there, and the sensor is working perfectly now!!
It’s all thanks to you… I don’t even know how to express my gratitude!
Thank you so much!!!
1 Like
yes, although, I still did it wrong, try this:
struct AnalogReadHelper : public Looper {
const char name() { return "AnalogReaderHelper"; }
explicit AnalogReadHelper(int pin) : AnalogReader(pin) { reader_.value_ = -1; }
void Loop() override {
if (!running_) {
if (reader_.Start()) {
running_ = true;
}
} else {
if (reader.Done()) {
running_ = false;
}
}
}
int Value() { return reader_.value_; }
bool running_ = false;
AnalogReader reader_;
};
AnalogReadHelper extendReader(blade4Pin);
AnalogReadHelper retractReader(10);
Although now I see that you already got it working. 
Thanks for the new code!
Yesterday’s code is still working fine, but very occasionally the extension sensor doesn’t respond after startup. I’m currently investigating whether this is a 5V issue or a problem that occurs the first time I use extendReader.
I’ll let you know the results once I try out the new code!
I’m currently trying this out on the 2.2 board as well. Data1 is working fine, but Data3 isn’t working properly.
Is it really impossible with version 2.2?
const int extendSensorPin = bladePin; //Data1 16
const int retractSensorPin = blade3Pin; //Data3 17
Looks like I mixed it up. Try Data4 / blade4Pin instead.
It was the same as with Data3Pin.
That’s odd. I think it should work.
I’ll have to do some testing, not sure when I’ll have time to do that though, it might take some time.
1 Like
I tried this new code as well, but it didn’t compile.
For now, I’ve changed the wiring to Data4, so I’ll wait for your test results!
This is the first Saber unit to become fully operational in version 3.9.
In terms of power consumption, I’d be happy if I could somehow build one that works on version 2.2 as well.
Thank you very much!!
1 Like
The 3.x uses more power?
The difference is supposed to be pretty small.