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.
Fork of FYDP_Final2 by
ACS712.h
00001 #ifndef ACS712_H 00002 #define ACS712_H 00003 00004 /**** 00005 This class calculates the current drawn by the robot. It requires that EVERYTHING else is turned off when 00006 calibration is in progress. 00007 Requirement: Turn off mouse sensors somehow. 00008 */ 00009 00010 #include "mbed.h" 00011 //#include "robot.h" 00012 00013 #define HIGH_CURRENT 130 //increase of current when switch is turned on [mA] 00014 #define LOW_CURRENT 36 //current draw when everything is turned off [mA] 00015 #define SWITCH_PIN PTB18//HIGH_CURRENT_SWITCH 00016 #define SENSOR_PIN PTC2//CURRENTSENSOR_PIN 00017 00018 #define CALIBRATION_SAMPLES 50 //the number of samples taken for the calibration 00019 00020 class ACS712 00021 { 00022 private: 00023 00024 AnalogIn sensor; //reads the value from current sensor 00025 DigitalOut currentSwitch; //turn this on to send current through a resistor 00026 00027 float b; //offset 00028 float m; //slope 00029 float current; //[mA] 00030 float sensor_val; //[% of 3.3V] 00031 00032 public: 00033 00034 ACS712(); 00035 void calibrate(); //calculates m and b 00036 float get_current(); //returns the current [mA] 00037 float read_sensor(); //reads sensor [% of 3.3V] 00038 float read_sensor(int n, int t); //reads sensor <n> times and returns the average 00039 }; 00040 00041 00042 00043 #endif
Generated on Tue Jul 12 2022 16:56:35 by
