CD74HC4067 library ported for mbed.

Committer:
scottohair
Date:
Sat Jan 20 10:52:09 2018 +0000
Revision:
0:7f158d69af5e
Library for the CDHC4067. Tested on NUCLEO-F401RE.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scottohair 0:7f158d69af5e 1 //CD74HC4067 Library based on bildr code: "http://bildr.org/2011/02/cd74hc4067-arduino/"
scottohair 0:7f158d69af5e 2 //Ported to mbed by Scott M. O'Hair
scottohair 0:7f158d69af5e 3 //
scottohair 0:7f158d69af5e 4 //sample code:
scottohair 0:7f158d69af5e 5 /*
scottohair 0:7f158d69af5e 6 #include "mbed.h"
scottohair 0:7f158d69af5e 7 #include "CD74HC4067.h"
scottohair 0:7f158d69af5e 8
scottohair 0:7f158d69af5e 9 Serial pc(PB_6, PA_10, 115200); //tx, rx
scottohair 0:7f158d69af5e 10
scottohair 0:7f158d69af5e 11 CD74HC4067 mux1(D8, D9, D12, D11, A0); //S0, S1, S2, S3, SIG
scottohair 0:7f158d69af5e 12
scottohair 0:7f158d69af5e 13 int main()
scottohair 0:7f158d69af5e 14 {
scottohair 0:7f158d69af5e 15 pc.printf("Running MUX test\n");
scottohair 0:7f158d69af5e 16 while(1) {
scottohair 0:7f158d69af5e 17 //Loop through and read all 16 values
scottohair 0:7f158d69af5e 18 for(int i = 0; i < 15; i++) {
scottohair 0:7f158d69af5e 19 mux1.currentState = mux1.readMux(i);
scottohair 0:7f158d69af5e 20 if (fabs(mux1.portState[i] - mux1.currentState) > BTN_NOISE_THRES) {
scottohair 0:7f158d69af5e 21 pc.printf("Value at channel %i is %f\n", i, mux1.currentState);
scottohair 0:7f158d69af5e 22 mux1.saveState(i, mux1.currentState);
scottohair 0:7f158d69af5e 23 }
scottohair 0:7f158d69af5e 24 }
scottohair 0:7f158d69af5e 25
scottohair 0:7f158d69af5e 26 }
scottohair 0:7f158d69af5e 27 }
scottohair 0:7f158d69af5e 28 */
scottohair 0:7f158d69af5e 29
scottohair 0:7f158d69af5e 30
scottohair 0:7f158d69af5e 31
scottohair 0:7f158d69af5e 32 #ifndef MBED_CD74HC4067_H
scottohair 0:7f158d69af5e 33 #define MBED_CD74HC4067_H
scottohair 0:7f158d69af5e 34
scottohair 0:7f158d69af5e 35 #include "mbed.h"
scottohair 0:7f158d69af5e 36
scottohair 0:7f158d69af5e 37 #define BTN_NOISE_THRES 0.018f //Define a threshold for the amount of analog change required
scottohair 0:7f158d69af5e 38
scottohair 0:7f158d69af5e 39 class CD74HC4067 {
scottohair 0:7f158d69af5e 40 public:
scottohair 0:7f158d69af5e 41 CD74HC4067(PinName S1, PinName S2, PinName S3, PinName S4, PinName SIG);
scottohair 0:7f158d69af5e 42 void saveState(uint8_t port, float state);
scottohair 0:7f158d69af5e 43 float readMux(uint8_t channel);
scottohair 0:7f158d69af5e 44 float currentState ;
scottohair 0:7f158d69af5e 45 float portState[16];
scottohair 0:7f158d69af5e 46
scottohair 0:7f158d69af5e 47 private:
scottohair 0:7f158d69af5e 48 DigitalOut _S0;
scottohair 0:7f158d69af5e 49 DigitalOut _S1;
scottohair 0:7f158d69af5e 50 DigitalOut _S2;
scottohair 0:7f158d69af5e 51 DigitalOut _S3;
scottohair 0:7f158d69af5e 52 AnalogIn _SIG;
scottohair 0:7f158d69af5e 53
scottohair 0:7f158d69af5e 54 };
scottohair 0:7f158d69af5e 55
scottohair 0:7f158d69af5e 56 #endif