Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE DebounceIn Motordriver PinDetect SDFileSystem mbed-rtos mbed
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
Generated on Sat Jul 16 2022 00:54:10 by
1.7.2