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.
Diff: Multiplexer.cpp
- Revision:
- 0:88f8e80dc5fd
- Child:
- 4:cc896bb62196
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Multiplexer.cpp Wed Mar 19 10:29:32 2014 +0000
@@ -0,0 +1,95 @@
+#include "Multiplexer.h"
+#include "mbed.h"
+
+DigitalOut sync(p5);
+DigitalOut sclk_mux(p6);
+DigitalOut din(p7);
+
+#define ENABLE 7
+#define CSA 6
+#define CSB 5
+#define UNUSED_BIT 4
+#define A3 3
+#define A2 2
+#define A1 1
+#define A0 0
+
+//Constructor & Destructor
+Multiplexer::Multiplexer(void)
+{
+ sclk_mux = 0;
+ sync = 1;
+ din = 0;
+
+ enable = false;
+ channel = 0;
+}
+Multiplexer::~Multiplexer(void)
+{
+}
+
+//GETTERS
+bool Multiplexer::Enabled(void)
+{
+ return(enable);
+}
+int Multiplexer::getChannel(void)
+{
+ return(channel);
+}
+
+//SETTERS
+void Multiplexer::Enable(void)
+{
+ enable = true;
+ Update();
+}
+void Multiplexer::Disable(void)
+{
+ enable = false;
+ Update();
+}
+void Multiplexer::setChannel(int newChannel)
+{
+ if(newChannel>=0 && newChannel<16)
+ {
+ channel = newChannel;
+ Update();
+ }
+}
+
+//updater
+void Multiplexer::Update(void)
+{
+
+ //onze data opmaken
+ char data = 0;
+ data |= !enable << ENABLE;
+ data |= 0 << CSA;
+ data |= 0 << CSB;
+ data |= 1 << UNUSED_BIT;
+ data |= channel;
+
+ //Timing diagrama uitvoeren
+ sclk_mux = 1;
+ wait_us(1);
+
+ sclk_mux = 0;
+ wait_us(1);
+
+ sync = 0;
+ for (int i = 7; i >= 0; i--)
+ {
+ sclk_mux = 1;
+ din = (data >> i) & 1;
+ wait_us(1);
+
+ sclk_mux = 0;
+ wait_us(1);
+ }
+
+ //terug standaard waarden
+ sclk_mux = 0;
+ sync = 1;
+ din = 0;
+}
\ No newline at end of file