Go Down

Topic: does not name a type problem [SOLVED] (Read 7186 times) previous topic - next topic

agniusm

Jan 08, 2014, 04:07 pm Last Edit: Jan 11, 2014, 11:37 am by agniusm Reason: 1
hi. So my programming sucks big time. I have this code:

Code: (.ino) [Select]
#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif
//#include <Streaming.h>
#include "Switch.h"

const byte spotWelderButtonPin = 7;
const byte spotWelder = 8;
const byte BCDswitch3 = 9;
const byte BCDswitch2 = 10;
const byte BCDswitch1 = 11;
const byte BCDswitch0 = 12;

const int preWeld_ms = 50;
const int step_ms = 50;
const int weldPause = 500;

Switch spotWelderButton(spotWelderButtonPin);

void setup()
{ Serial.begin(9600);
 pinMode(BCDswitch0, INPUT_PULLUP);
 pinMode(BCDswitch1, INPUT_PULLUP);
 pinMode(BCDswitch2, INPUT_PULLUP);
 pinMode(BCDswitch3, INPUT_PULLUP);  
 pinMode(spotWelder, OUTPUT);
}

void loop()
{ spotWelderButton.poll();
 if(spotWelderButton.pushed()) weldCyclus(BCDswitch() * step_ms);
}

void weldCyclus(int weldTime_ms)
{ pulseSpotWelder(preWeld_ms);
 delay(weldPause);
 pulseSpotWelder(weldTime_ms);
}

void pulseSpotWelder(int ms)
{ digitalWrite(spotWelder, 1);
 delay(ms);
 digitalWrite(spotWelder, 0);
 //Serial << ms << endl;  
}

int BCDswitch()
{ int bcd;
 bitWrite(bcd, 0, !digitalRead(BCDswitch0));
 bitWrite(bcd, 1, !digitalRead(BCDswitch1));
 bitWrite(bcd, 2, !digitalRead(BCDswitch2));
 bitWrite(bcd, 3, !digitalRead(BCDswitch3));
 return bcd;
}

i have put 2 files to library/Switch, Switch.h and Switch.cpp

Code: (Switch.h) [Select]
#ifndef SWITCH_H
#define SWITCH_H

class Switch
{
public:
 Switch(byte _pin, byte PinMode=INPUT_PULLUP, bool polarity=LOW, int debounceDelay=50, int longPressDelay=400, int doubleClickDelay=250);
 bool poll(); // Returns 1 if switched  
 bool switched(); // will be refreshed by poll()
 bool on();
 bool pushed(); // will be refreshed by poll()
 bool released(); // will be refreshed by poll()
 bool longPress(); // will be refreshed by poll()
 bool doubleClick(); // will be refreshed by poll()

 unsigned long _switchedTime, pushedTime;
 
protected:
 const byte pin;
 const int debounceDelay, longPressDelay, doubleClickDelay;
 const bool polarity;
 bool level, _switched, _longPress, longPressLatch, _doubleClick;
};

#endif


Code: (Switch.cpp) [Select]

#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif
#include "Switch.h"

// level(0)                
Switch::Switch(byte _pin, byte PinMode, bool polarity, int debounceDelay, int longPressDelay, int doubleClickDelay):
pin(_pin), polarity(polarity), debounceDelay(debounceDelay), longPressDelay(longPressDelay), doubleClickDelay(doubleClickDelay)
{ pinMode(pin, PinMode);
 _switchedTime = millis();
 level = digitalRead(pin);
}

bool Switch::poll()
{ _longPress = _doubleClick = false;
 bool newlevel = digitalRead(pin);  

 if(!longPressLatch)
 { _longPress = on() && ((long)(millis() - pushedTime) > longPressDelay); // true just one time between polls
   longPressLatch = _longPress; // will be reset at next switch  
 }

 if((newlevel != level) & (millis() - _switchedTime >= debounceDelay))
 { _switchedTime = millis();
   level = newlevel;
   _switched = 1;
   longPressLatch = false;

   if(pushed())
   { _doubleClick = (long)(millis() - pushedTime) < doubleClickDelay;
     pushedTime = millis();
   }
   return _switched;
 }
 return _switched = 0;
}

bool Switch::switched()
{ return _switched;
}

bool Switch::on()
{ return !(level^polarity);
}

bool Switch::pushed()
{ return _switched && !(level^polarity);
}

bool Switch::released()
{ return _switched && (level^polarity);
}

bool Switch::longPress()
{ return _longPress;
}

bool Switch::doubleClick()
{ return _doubleClick;
}


Code: (Error message) [Select]
In file included from Switch.ino:7:
C:\Users\Agnius\Documents\Arduino\libraries\Switch/Switch.h:2: error: 'Switch' does not name a type
C:\Users\Agnius\Documents\Arduino\libraries\Switch/Switch.h:6: error: 'without' does not name a type
Switch:20: error: 'Switch' does not name a type
Switch.ino: In function 'void loop()':
Switch:32: error: 'spotWelderButton' was not declared in this scope
Switch.ino: At global scope:
Switch:57: error: 'i' does not name a type
In file included from Switch.ino:92:
C:\Users\Agnius\Documents\Arduino\libraries\Switch/Switch.h:6: error: 'without' does not name a type
Switch:102: error: 'Switch' has not been declared
Switch.ino: In function 'bool poll()':
Switch:103: error: '_longPress' was not declared in this scope
Switch:103: error: '_doubleClick' was not declared in this scope
Switch:104: error: 'pin' was not declared in this scope
Switch:106: error: 'longPressLatch' was not declared in this scope
Switch:107: error: 'on' was not declared in this scope
Switch:107: error: 'pushedTime' was not declared in this scope
Switch:107: error: 'longPressDelay' was not declared in this scope
Switch:111: error: 'level' was not declared in this scope
Switch:111: error: '_switchedTime' was not declared in this scope
Switch:111: error: 'debounceDelay' was not declared in this scope
Switch:114: error: '_switched' was not declared in this scope
Switch:115: error: 'longPressLatch' was not declared in this scope
Switch:117: error: 'pushed' was not declared in this scope
Switch:118: error: 'pushedTime' was not declared in this scope
Switch:118: error: 'doubleClickDelay' was not declared in this scope
Switch:123: error: '_switched' was not declared in this scope
Switch.ino: At global scope:
Switch:126: error: 'Switch' has not been declared
Switch.ino: In function 'bool switched()':
Switch:127: error: '_switched' was not declared in this scope
Switch.ino: At global scope:
Switch:130: error: 'Switch' has not been declared
Switch.ino: In function 'bool on()':
Switch:131: error: 'level' was not declared in this scope
Switch:131: error: 'polarity' was not declared in this scope
Switch.ino: At global scope:
Switch:134: error: 'Switch' has not been declared
Switch.ino: In function 'bool pushed()':
Switch:135: error: '_switched' was not declared in this scope
Switch:135: error: 'level' was not declared in this scope
Switch:135: error: 'polarity' was not declared in this scope
Switch.ino: At global scope:
Switch:138: error: 'Switch' has not been declared
Switch.ino: In function 'bool released()':
Switch:139: error: '_switched' was not declared in this scope
Switch:139: error: 'level' was not declared in this scope
Switch:139: error: 'polarity' was not declared in this scope
Switch.ino: At global scope:
Switch:142: error: 'Switch' has not been declared
Switch.ino: In function 'bool longPress()':
Switch:143: error: '_longPress' was not declared in this scope
Switch.ino: At global scope:
Switch:146: error: 'Switch' has not been declared
Switch.ino: In function 'bool doubleClick()':
Switch:147: error: '_doubleClick' was not declared in this scope

Could someone help out? Thanks

Delta_G

Can you post the error that you got?  If you can tell us which line it highlights that would be really helpful too.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

PeterH

I suggest you use code tags rather than quote tags to post code. You can include the name of the file in the tag to make it clearer when you are posting multiple files:

[ code=file.cpp ] gives

Code: (file.cpp) [Select]

PaulS

I copied your Switch.h and Switch.cpp contents into appropriately named files in the appropriately named directory. I copied your sketch into the IDE, and selected verify. I got just one error:
Quote
Binary sketch size: 3,196 bytes (of a 30,720 byte maximum)
The art of getting good answers lies in asking good questions.

agniusm

#4
Jan 10, 2014, 03:48 pm Last Edit: Jan 10, 2014, 03:54 pm by agniusm Reason: 1
Thanks guys. I have corrected my first post. It highlights this line:
Code: [Select]
Switch spotWelderButton(spotWelderButtonPin);
I was advised to look here :http://www.avdweb.nl/arduino/troubleshooting.html but cant make sense of it

UKHeliBob

Read Pauls post carefully.  It contains clues as to the probably cause of the problem that you are having.

HINT - where exactly (the full path)  have you put the library files and how did you do it ? 
Are you using a Mac, PC or Linux ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

agniusm

#6
Jan 11, 2014, 09:51 am Last Edit: Jan 11, 2014, 09:55 am by agniusm Reason: 1
I have just created folder /program files/arduino/libraries/switch and created 2 text files, copied content and named them switch with extensions .h and .cpp
Its windows 7 32bit. My .ino is saved in documents folder. I have arduino mini and simple stuff uploads OK but that probably has nothing to do with the errors I get.
I have reinstalled Arduino ide with same results. Must be something stupid that I am missing.

pYro_65

Don't mix case!!!

Switch != switch

You can't use switch as it is reserved, your library folder must be Switch, same as the header and source files.
Forum Mod anyone?
https://arduino.land/Moduino/

agniusm

Thank you. Yes, i have them case sensitive, just posted here incorrectly. Here are some screenshots to eliminate the doubt:



UKHeliBob

Quote
I have just created folder /program files/arduino/libraries/switch

That's what's wrong.  The Switch library (case matters) should be in the libraries folder where your programs are saved.

As an example, this is the path to my user contributed libraries folder C:\Users\Bob\Documents\Arduino\libraries
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

PaulS

Looking carefully at the messages you posted, I have some question.

Quote
C:\Users\Agnius\Documents\Arduino\libraries\Switch/Switch.h:2: error: 'Switch' does not name a type
C:\Users\Agnius\Documents\Arduino\libraries\Switch/Switch.h:6: error: 'without' does not name a type

The string "without" does not appear in the header file you posted. So, why is the compiler finding it in the code you are trying to compile? The only answer that makes any sense to me is that the code you posted is not the same as the code you are trying to compile. So, what do you have to say about that?
The art of getting good answers lies in asking good questions.

agniusm

I have checked the Documents folder and the library exists @: C:\Users\Agnius\Documents\Arduino\libraries\Switch

You right, perhaps i had copy paste error but i still get this error after correction:
Code: (error) [Select]

In file included from Switch.ino:7:
C:\Users\Agnius\Documents\Arduino\libraries\Switch/Switch.h:2: error: 'Switch' does not name a type
C:\Users\Agnius\Documents\Arduino\libraries\Switch/Switch.h:6: error: 'without' does not name a type
Switch:20: error: 'Switch' does not name a type
Switch.ino: In function 'void loop()':
Switch:32: error: 'spotWelderButton' was not declared in this scope

AWOL

How about posting source?
Not a screenshot.
Not a bunch of disembodied error messages.
Source.

agniusm

OK. Sorted. Think there was copy/paste error along the line somewhere that i have missed. Redone all and now it compiles good. Thanks for the tips. Check, double check, triple check and then check again some more is my lesson.
Thank you

Go Up