does not name a type problem [SOLVED]

hi. So my programming sucks big time. I have this code:

#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

#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
#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;
}
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

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

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


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:

Binary sketch size: 3,196 bytes (of a 30,720 byte maximum)

Thanks guys. I have corrected my first post. It highlights this line:

Switch spotWelderButton(spotWelderButtonPin);

I was advised to look here :Arduino tips but cant make sense of it

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 ?

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.

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.

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



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

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

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?

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:

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

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

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

i am having this problem ide keep saying currentMillis do not mean a type how can i fix it

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20,4);

const int triacPin = 3;
const int mosfatPin = 4;
const int upButtonPin = 15;
const int downButtonPin = 16;
const int pumpButtonPin = 17;
const int bzzerPin = 18;
const int desolderingIbutton = 19;
const int desolLedPin = 26;
const int redLedPin = 27;
const int greenLedPin = 29;
const int relayPin = 30;

int desolderingIButtonNew;
int desolderingIBUttonOld = 1;

int relayPinState = 0;
int DesolLedPinState = 0;

int thermoDO = 9;
int thermoCS = 10;
int thermoCLK = 13;
//MAX6675 thermocouple(thermoCK, thermoCS; thermoCLK);

// variables
int last_CHI_state = 0;
bool zero_cross_detected = false;
int firing_delay = 7400;

////////////////////////////////////////////////////////////////////////////////
int MAXIMUM_firing_delay = 7400;

unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
int temp_read_Delay = 500;
int temp_temperature = 0;
bool upButtonPressed = false;
bool downBttonPressed = false;

//pid variable
float pid_error = 0;
float previous_error = 0;
float elapsedTime, Time, timePrev;
int PID_Value = 0;
//pid_constant
int kp = 203; int ki = 7.2; int kd = 1.04;
int pid_p = 0; int PID_i = 0; int PID_d = 0;

void setup() {
pinMode(triacPin, OUTPUT);
pinMode(mosfatPin, OUTPUT);
pinMode(upButtonPin, INPUT);
pinMode(downButtonPin, INPUT);
pinMode(bzzerPin, OUTPUT);
pinMode(desolderingIbutton, INPUT);
pinMode(desolLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);

}

void loop() {
desolderingIButtonNew = digitalRead(desolderingIbutton);
if(desolderingIBUttonOld == 0 && desolderingIButtonNew == 1){
digitalWrite(relayPin && redLedPin, HIGH);
relayPin && desolLedPin == 1;
}
else{
digitalWrite(relayPin && desolLedPin, LOW);
relayPinState = 0;
DesolLedPinState = 0;
delay(100);

}
}
currentMillis = millis();
if(currentMillis - previousMillis >= temp_read_delay);
previousMillis += temp_read_deiay;
real_temperature = thermocouple.readCelsius();
real_temperature = thermocouple.readFahrenheit ();

PID_error = setpoint - real_temperature;
if(PID_error > 30)
{PID_i = 0;}

PID_P = kp * PID_error;
PID_i = PID_i + (ki * PID_error

All of this is outside any function:

 currentMillis = millis();
 if(currentMillis - previousMillis >= temp_read_delay);
 previousMillis += temp_read_deiay;
 real_temperature = thermocouple.readCelsius();
 real_temperature = thermocouple.readFahrenheit ();

 PID_error = setpoint - real_temperature;
 if(PID_error > 30)
 {PID_i = 0;}

 PID_P = kp * PID_error;
 PID_i = PID_i + (ki * PID_error

Plus it isn't even complete. Maybe post ALL of your code.