Hey there, thanks for looking! I’d like some fresh eyes to help me find what I keep overlooking! First time posting, hope I understood the guidelines well enough!
The project I’m working on is an Iron Man helmet that uses two servos to open and close the face plate using an MPR121 capacitive touch sensor.
This is being edited from code used in this project:
I thought I could duplicate the majority of the code (took out arc reactor parts from OG code) and create my oppositely running servo by adding an R (reverse) to the duplicates identifiers (e.g. helmetServo and helmetServoR for the other one). So far it seems like it should be just about there. I’ve ironed out issues for a few hours and am finally stuck with this error about classes:
exit status 1
‘class HELMETR’ has no member named ‘UpdateR’
Without the duplicate R lines, the program compiled and ran. But I needed another servo on the other side for smoother rotation / stability. I could try to add another gear in the helmet to offset the rotations, but I’d like to solve it in the code if I can before going that extreme! Thank you for your time and patience with me, folks!
EDIT: fixed first error, thanks for catching that TheMemberFormerlyKnownAsAWOL!
Here is the most recent error:
exit status 1
‘expected unqualified-id before numeric constant’ highlighting ‘#define helmetPinR 10’
#include <Wire.h>
#include <Servo.h>
#include <Adafruit_MPR121.h>
/////////////////////////////////
#define helmetPin 9
#define helmetPinR 10
#define DOWNANGLE 0
#define UPANGLE 160
#define DOWNANGLER 0
#define UPANGLER 160
#define UP 1
#define DOWN 0
#define UPR 1
#define DOWNR 0
////////////////////////
Servo helmetServo;
int helmetPin;
boolean helmetUp;
long lastSwitched;
int downAngle;
int upAngle;
int directionality;
long lastFlipped;
boolean flip, flipping;
int currentPos;
long lastMoved;
//////////////////////////
Servo helmetServoR;
int helmetPinR;
boolean helmetUpR;
long lastSwitchedR;
int downAngleR;
int upAngleR;
int directionalityR;
long lastFlippedR;
int currentPosR;
long lastMovedR;
///////////////////////////
class HELMET
{
public:
HELMET(int pinNumber, boolean helmetState, int down, int up)
{
helmetPin = pinNumber;
helmetUp = helmetState;
downAngle = down;
upAngle = up;
}
int getHelmetPin() {
return helmetPin;
}
void setHelmetPin(int pinNumber) {
helmetPin = pinNumber;
}
boolean getHelmetUp() {
return helmetUp;
}
void setHelmetUp(boolean helmetState) {
helmetUp = helmetState;
}
long getLastSwitched() {
return lastSwitched;
}
void setLastSwitched(long timeSwitched) {
lastSwitched = timeSwitched;
}
int getDownAngle() {
return downAngle;
}
void setDownAngle(int angle) {
downAngle = angle;
}
int getUpAngle() {
return upAngle;
}
void setUpAngle(int angle) {
upAngle = angle;
}
////////////////////////////////////////////////////
void init()
{
helmetServo.attach(helmetPin);
helmetServo.write(upAngle);
lastSwitched = millis();
flip = false;
flipping = false;
lastFlipped = 0;
lastMoved = 0;
}
///////////////////////////////////////////////////
void flipFaceplate()
{
if ((millis() - lastFlipped) > 500 )
{
lastFlipped = millis();
if (flip)
{
flipping = true;
currentPos = 0;
directionality = UP;
}
else
{
flipping = true;
currentPos = 160;
directionality = DOWN;
}
flip = !flip;
}
}
//////////////////////////////////////////////////////
void Update()
{
if ( flipping & (millis() - lastMoved) >= 15 )
{
lastMoved = millis();
if ( directionality == UP )
{
currentPos = currentPos + 3;
}
else
{
currentPos = currentPos - 3;
}
Serial.print("current position: "); Serial.print(currentPos);
helmetServo.write(currentPos);
}
if ((currentPos >= upAngle) || (currentPos <= downAngle)) {
flipping = false;
}
}
};
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
class HELMETR
{
public:
HELMETR(int pinNumberR, boolean helmetStateR, int downR, int upR)
{
helmetPinR = pinNumberR;
helmetUpR = helmetStateR;
downAngleR = downR;
upAngleR = upR;
}
int getHelmetPinR() {
return helmetPinR;
}
void setHelmetPinR(int pinNumberR) {
helmetPinR = pinNumberR;
}
boolean getHelmetUpR() {
return helmetUpR;
}
void setHelmetUpR(boolean helmetStateR) {
helmetUpR = helmetStateR;
}
long getLastSwitchedR() {
return lastSwitchedR;
}
void setLastSwitchedR(long timeSwitchedR) {
lastSwitchedR = timeSwitchedR;
}
int getDownAngleR() {
return downAngleR;
}
void setDownAngleR(int angleR) {
downAngleR = angleR;
}
int getUpAngleR() {
return upAngleR;
}
void setUpAngleR(int angle) {
upAngleR = angle;
}
//////////////////////////////////////////////////////////
void initR()
{
helmetServoR.attach(helmetPinR);
helmetServoR.write(upAngleR);
lastSwitchedR = millis();
flip = false;
flipping = false;
lastFlippedR = 0;
lastMovedR = 0;
}
//////////////////////////////////////////////////////////
void flipFaceplateR()
{
int directionalityR;
long lastFlippedR;
boolean flip, flipping;
int currentPosR;
long lastMovedR;
{
if ((millis() - lastFlippedR) > 500 )
{
lastFlippedR = millis();
if (flip)
{
flipping = true;
currentPosR = 0;
directionalityR = UPR;
}
else
{
flipping = true;
currentPosR = 160;
directionalityR = DOWNR;
}
flip = !flip;
}
}
/////////////////////////////////////////////////////////
void UpdateR()
{
if ( flipping & (millis() - lastMovedR) >= 15 )
{
lastMovedR = millis();
if ( directionalityR == UP )
{
currentPosR = currentPosR + 3;
}
else
{
currentPosR = currentPosR - 3;
}
Serial.print("current position: "); Serial.print(currentPosR);
Servo helmetServoR;
helmetServoR.write(currentPosR);
}
int downAngleR;
int upAngleR;
if ((currentPosR >= upAngleR) || (currentPosR <= downAngleR)) {
flipping = false;
}
}
};
///////////////////////////////////////////////////////////////
HELMET helmet(helmetPin, true, DOWNANGLE, UPANGLE);
HELMETR helmetR(helmetPinR, true, DOWNANGLER, UPANGLER);
/////////////////////////////////////////////////////////
Adafruit_MPR121 touchControl = Adafruit_MPR121();
uint16_t currTouched = 0;
///////////////////////////////////////////////////////////////
void setup(void)
{ Serial.begin(9600);
helmet.init();
if (!touchControl.begin(0x5A)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 found!");
}
void loop(void)
{
currTouched = touchControl.touched();
Serial.print("touched: "); Serial.println(currTouched);
switch (currTouched)
{
case 1:
helmet.flipFaceplate();
helmetR.flipFaceplateR();
break;
case 2:
break;
}
helmet.Update();
helmetR.UpdateR();
};