Change of code in Solenoid taken from Jim Hamblen's Notebook page on solenoids. https://developer.mbed.org/users/4180_1/notebook/an-introduction-to-solenoids/ Changed action of Solenoid class. Removed off delay functionality. Added on delay functionality and renamed for clarity between on delay and on time.
Fork of Solenoid by
Revision 1:b87c9e1546c5, committed 2015-12-09
- Comitter:
- mitchpang
- Date:
- Wed Dec 09 19:46:01 2015 +0000
- Parent:
- 0:bd163b4ce456
- Commit message:
- Changed action of Solenoid class. Removed off delay functionality. Added on delay functionality and renamed for clarity between on delay and on time.
Changed in this revision
Solenoid.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r bd163b4ce456 -r b87c9e1546c5 Solenoid.h --- a/Solenoid.h Tue Nov 24 09:36:27 2015 +0000 +++ b/Solenoid.h Wed Dec 09 19:46:01 2015 +0000 @@ -8,39 +8,39 @@ class Solenoid { public: - Solenoid (PinName pin, float ondelay=0.5, float offdelay=2.0); + Solenoid (PinName pin, float onTime=0.25, float onDelay=0.095); void write(bool state); Solenoid& operator= (bool value); private: void Solenoid_Off_Int(); + void Solenoid_On_Int(); DigitalOut _pin; Timeout tint; - Timer offtimer; + Timeout tondelay; float ontime; - float offtime; + float delaytime; }; -Solenoid::Solenoid(PinName pin, float ondelay, float offdelay) : _pin(pin), ontime(ondelay), offtime(offdelay) +Solenoid::Solenoid(PinName pin, float onTime, float onDelay) : _pin(pin), ontime(onTime), delaytime(onDelay) { _pin=0; - offtimer.start(); } void Solenoid::Solenoid_Off_Int() { _pin=0;//OFF timer interrupt routine to auto turn off solenoid - offtimer.start(); //start off-time delay count +} +void Solenoid::Solenoid_On_Int() +{ + _pin = 1; + tint.attach(this,&Solenoid::Solenoid_Off_Int,ontime);//setup a timer interrupt for on time } void Solenoid::write(bool value) { if (value!=0) {//ON so do auto off with timer interrupt - while(offtimer.read() < offtime); //wait for min OFF time before next ON allowed - offtimer.stop(); - offtimer.reset(); //reset off timer delay count - tint.attach(this,&Solenoid::Solenoid_Off_Int,ontime);//setup a timer interrupt for on time + tondelay.attach(this,&Solenoid::Solenoid_On_Int,delaytime); } else - offtimer.start(); //solenoid turned off with a write call (not timers) so start off count - _pin = value; + _pin = value;//solenoid turned off with a write call (not timers) } Solenoid& Solenoid::operator= (bool value) {