Added all useful libraires
This commit is contained in:
31
lib/MAX6675/max6675.cpp
Normal file
31
lib/MAX6675/max6675.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
#include "max6675.h"
|
||||
|
||||
max6675::max6675(PinName miso, PinName sclk, PinName cs) :
|
||||
max(NC, miso, sclk), _cs(cs)
|
||||
{
|
||||
max.format(16,1); // set 16 bit SPI format
|
||||
max.frequency(400000);
|
||||
}
|
||||
|
||||
float max6675::gettemp(int cf)
|
||||
{
|
||||
float temp = 0;
|
||||
int tempByte= 0;
|
||||
|
||||
_cs = 0;
|
||||
wait_us(1); // wait to stablize
|
||||
tempByte = max.write(0);
|
||||
wait_us(1); // wait to finish
|
||||
_cs = 1;
|
||||
|
||||
if (tempByte & (1<<2)) { // faulty or no sensor connected
|
||||
return -99;
|
||||
} else {
|
||||
temp = (tempByte)/32.0f;
|
||||
}
|
||||
if(cf) {
|
||||
temp = (temp*9.0f/5.0f) + 32.0f; // Convert value to ˚F
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
49
lib/MAX6675/max6675.h
Normal file
49
lib/MAX6675/max6675.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef max6675_h
|
||||
#define max6675_h
|
||||
|
||||
#include "mbed.h"
|
||||
|
||||
/*
|
||||
#include "mbed.h"
|
||||
#include "max6675.h"
|
||||
|
||||
max6675 sensor(D5,D3,D6); //miso, sclk, cs
|
||||
Serial pc(USBTX,USBRX);
|
||||
|
||||
int main()
|
||||
{
|
||||
pc.baud(921600);
|
||||
pc.printf("\033[0m\033[2J\033[HMAX6675 Thermocouple!\r\n\n\n");
|
||||
|
||||
int cf = 0; // 0 Centigrade, 1 Fahrenheit
|
||||
|
||||
while (1) {
|
||||
|
||||
float temp = sensor.gettemp(cf);
|
||||
if (cf) {
|
||||
printf(" Temp: %4.2f%cF \n\033[2K\033[1A",temp,176);
|
||||
} else {
|
||||
printf(" Temp: %4.2f%cC \n\033[2K\033[1A",temp,176);
|
||||
}
|
||||
wait_ms(250); // requires 250mS for temperature conversion process
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
class max6675
|
||||
{
|
||||
public:
|
||||
|
||||
max6675(PinName miso, PinName sclk, PinName cs);
|
||||
|
||||
// read temperature 0 Centigrade, 1 Fahrenheit
|
||||
float gettemp(int cf);
|
||||
|
||||
private:
|
||||
SPI max;
|
||||
DigitalOut _cs;
|
||||
Timer t;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user