Files at this revision

API Documentation at this revision

Comitter:
evgeniik
Date:
Fri Jul 17 09:37:04 2020 +0000
Commit message:
Lib for 16to1 analog MUX/DMUX (74HC4067)

Changed in this revision

Multi_16.cpp Show annotated file Show diff for this revision Revisions of this file
Multi_16.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Multi_16.cpp	Fri Jul 17 09:37:04 2020 +0000
@@ -0,0 +1,31 @@
+ #include "Multi_16.h"
+    
+    Mux::Mux(PinName s0Pin, PinName s1Pin, PinName s2Pin, PinName s3Pin, PinName enPin):
+    _s0(s0Pin), _s1(s1Pin), _s2(s2Pin), _s3(s3Pin), _en(enPin)
+    {
+    }
+    
+    void Mux::set_channel(int n)
+    {        
+        if (n < 16) {
+            bool state[4];
+            state[3] = 0b00001000 & n;  _s3 = state[3];
+            state[2] = 0b00000100 & n;  _s2 = state[2];
+            state[1] = 0b00000010 & n;  _s1 = state[1];
+            state[0] = 0b00000001 & n;  _s0 = state[0];
+            //printf("s0 = %d, s1 = %d, s2 = %d, s3 = %d\n", state[0], state[1], state[2], state[3]);
+            open();
+        }
+        else{
+            printf("Out of range.     Mux is closed \n");
+            close();
+        }
+    }
+    
+    void Mux::open(){
+        _en = false;
+    }
+    
+    void Mux::close(){
+        _en = true;
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Multi_16.h	Fri Jul 17 09:37:04 2020 +0000
@@ -0,0 +1,22 @@
+#ifndef MULTI_16_H
+#define MULTI_16_H
+
+#include "mbed.h"
+
+class Mux
+{
+    public:
+        Mux(PinName enPin, PinName s0Pin, PinName s1Pin, PinName s2Pin, PinName s3Pin);
+        
+        void set_channel(int n);
+        void open(void);
+        void close(void);
+        
+    private:
+        DigitalOut _en;
+        DigitalOut _s0;
+        DigitalOut _s1;
+        DigitalOut _s2;
+        DigitalOut _s3;
+};
+#endif
\ No newline at end of file