upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions

API for the Electromagnet. More...

Detailed Description

The Electromagnet can hold up to 1 kg (approximately 2.2 lbs)

electromagnet.jpg
// The was tested with the Electromagnetic Module
// Instantiate a Electromagnet on digital pin D2
upm::Electromagnet magnet(2);
cout << "Starting up magnet...." << endl;
magnet.off();
bool magnetState = false;
float time_passed = get_time();
// Turn magnet on and off every 5 seconds
while (shouldRun) {
if ((get_time() - time_passed) > 5.0) {
magnetState = !magnetState;
if (magnetState)
magnet.on();
else
magnet.off();
cout << "Turning magnet " << ((magnetState) ? "on" : "off") << endl;
time_passed = get_time();
}
}

Public Member Functions

 Electromagnet (int pin)
 
 ~Electromagnet ()
 
void on ()
 
void off ()
 

Constructor & Destructor Documentation

Electromagnet ( int  pin)

Electromagnet constructor

Parameters
pinDigital pin to use

Electromagnet destructor

Member Function Documentation

void on ( )

Turns the magnet on

void off ( )

Turns the magnet off


The documentation for this class was generated from the following files: