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