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.
CD74HC4067.cpp
00001 //CD74HC4067 Library based on bildr code: "http://bildr.org/2011/02/cd74hc4067-arduino/" 00002 //Ported to mbed by Scott M. O'Hair 00003 00004 #include "CD74HC4067.h" 00005 #include "mbed.h" 00006 00007 00008 CD74HC4067::CD74HC4067(PinName S1, PinName S2, PinName S3, PinName S4, PinName SIG) : _S0(S1), _S1(S2), _S2(S3), _S3(S4), _SIG(SIG) 00009 { 00010 //initialize port state to zero 00011 for (uint8_t i = 0; i < 15; i++) { 00012 portState[i] = 0.0; 00013 } 00014 00015 //pull all pins low 00016 _S0 = 0; 00017 _S1 = 0; 00018 _S2 = 0; 00019 _S3 = 0; 00020 00021 } 00022 00023 void CD74HC4067::saveState(uint8_t port, float state) 00024 { 00025 this->portState[port] = state; 00026 } 00027 00028 float CD74HC4067::readMux(uint8_t channel) 00029 { 00030 DigitalOut controlPin[] = {_S0, _S1, _S2, _S3}; 00031 00032 uint8_t muxChannel[16][4]= { 00033 {0,0,0,0}, //channel 0 00034 {1,0,0,0}, //channel 1 00035 {0,1,0,0}, //channel 2 00036 {1,1,0,0}, //channel 3 00037 {0,0,1,0}, //channel 4 00038 {1,0,1,0}, //channel 5 00039 {0,1,1,0}, //channel 6 00040 {1,1,1,0}, //channel 7 00041 {0,0,0,1}, //channel 8 00042 {1,0,0,1}, //channel 9 00043 {0,1,0,1}, //channel 10 00044 {1,1,0,1}, //channel 11 00045 {0,0,1,1}, //channel 12 00046 {1,0,1,1}, //channel 13 00047 {0,1,1,1}, //channel 14 00048 {1,1,1,1} //channel 15 00049 }; 00050 00051 //loop through the 4 sig 00052 for(uint8_t i = 0; i < 4; i++) { 00053 controlPin[i] = muxChannel[channel][i]; 00054 } 00055 00056 //read the value at the SIG pin 00057 float val = _SIG.read(); 00058 00059 //return the value 00060 return val; 00061 }
Generated on Thu Jul 14 2022 06:26:51 by
1.7.2