Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
CD4051.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 28.09.2013 13:43:34 CEST
3 // File: CD4051.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __CD4051_HEADER
12 #define __CD4051_HEADER
13 
14 //8:1 MUX
15 
16 #include "../tool/out_pin.hpp"
17 #include "../tool/fake_button.hpp"
18 
19 namespace device {
20  template<uint8_t master, uint8_t d0, uint8_t d1, uint8_t d2, bool high_state = 0>
21  class CD4051_class {
22  public:
24  d0_ = 0;
25  d1_ = 0;
26  d2_ = 0;
27 
28  if(high_state == 0)
29  pinMode(master, INPUT_PULLUP);
30  else
31  pinMode(master, INPUT);
32  }
33  void update() {
34  #define READ(x) in_[x].update(high_state == digitalRead(master));
35 
36  READ(0)
37  d0_ = 1;
38  READ(1)
39  d1_ = 1;
40  READ(3)
41  d0_ = 0;
42  READ(2)
43  d2_ = 1;
44  READ(6)
45  d0_ = 1;
46  READ(7)
47  d1_ = 0;
48  READ(5)
49  d0_ = 0;
50  READ(4)
51  d2_ = 0;
52 
53  #undef READ
54  }
55  template<typename T>
56  void copy(T & vector, uint8_t const & pos) {
57  for(uint8_t i = 0; i < 8; ++i) {
58  vector[pos + i] = in_[i].state();
59  }
60  }
61  tool::fake_button_class const & operator[](uint8_t const & pos) const {
62  return in_[pos];
63  }
64  private:
68 
70  };
71 }//end namespace device
72 
73 #endif //__CD4051_HEADER
#define READ(x)
Definition: CD4051.hpp:21
void copy(T &vector, uint8_t const &pos)
Definition: CD4051.hpp:56
tool::fake_button_class const & operator[](uint8_t const &pos) const
Definition: CD4051.hpp:61
void update()
Definition: CD4051.hpp:33
CD4051_class()
Definition: CD4051.hpp:23