Adam Lawrence / Mbed 2 deprecated smartSafe

Dependencies:   4DGL-uLCD-SE DebounceIn Motordriver PinDetect SDFileSystem mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers solenoid.cpp Source File

solenoid.cpp

00001 #include "mbed.h"
00002 #include "solenoid.h"
00003 Solenoid::Solenoid(PinName pin, float ondelay, float offdelay) : _pin(pin), ontime(ondelay), offtime(offdelay)
00004 {
00005     _pin=0;
00006     offtimer.start();
00007  
00008 }
00009 void Solenoid::Solenoid_Off_Int()
00010 {
00011     _pin=0;//OFF timer interrupt routine to auto turn off solenoid
00012     offtimer.start(); //start off-time delay count
00013 }
00014 void Solenoid::write(bool value)
00015 {
00016     if (value!=0) {//ON so do auto off with timer interrupt
00017         while(offtimer.read() < offtime); //wait for min OFF time before next ON allowed
00018         offtimer.stop();
00019         offtimer.reset(); //reset off timer delay count
00020         tint.attach(this,&Solenoid::Solenoid_Off_Int,ontime);//setup a timer interrupt for on time
00021     } else
00022         offtimer.start(); //solenoid turned off with a write call (not timers) so start off count
00023     _pin = value;
00024 }
00025 Solenoid& Solenoid::operator= (bool value)
00026 {
00027     write(value);
00028     return *this;
00029 }
00030