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.
MCP3008.cpp
00001 /**by Austin Saunders 00002 00003 */ 00004 00005 #include <mbed.h> 00006 #include "MCP3008.h" 00007 00008 MCP3008::MCP3008(PinName mosi, PinName miso, PinName clk, PinName cs) 00009 : _spi(mosi,miso,clk), 00010 _cs(cs), 00011 _vref(3.3) 00012 { 00013 _spi.frequency(1000000); 00014 _spi.format(8,0); 00015 _cs = 1; 00016 } 00017 00018 int 00019 MCP3008::read(int ch) 00020 { 00021 _cs = 0; 00022 _spi.write(0x01); 00023 _data1 = _spi.write(0x80|(ch<<4)); 00024 _data2 = _spi.write(0x00); 00025 int adb = (_data1<<8) | _data2; 00026 adb = (adb & 0x03FF); 00027 _cs = 1; 00028 float ain = (adb*_vref)/1023; 00029 return adb; 00030 }
Generated on Sun Jul 17 2022 02:13:36 by
1.7.2