Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
CD4067.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: CD4067.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 __CD4067_HEADER
12 #define __CD4067_HEADER
13 
14 //16: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, uint8_t d3, bool high_state = 0>
21  class CD4067_class {
22  public:
24  d0_ = 0;
25  d1_ = 0;
26  d2_ = 0;
27  d3_ = 0;
28 
29  if(high_state == 0)
30  pinMode(master, INPUT_PULLUP);
31  else
32  pinMode(master, INPUT);
33  }
34  void update() {
35  #define READ(x) in_[x].update(high_state == digitalRead(master));
36 
37  READ(0)
38  d0_ = 1;
39  READ(1)
40  d1_ = 1;
41  READ(3)
42  d0_ = 0;
43  READ(2)
44  d2_ = 1;
45  READ(6)
46  d0_ = 1;
47  READ(7)
48  d1_ = 0;
49  READ(5)
50  d0_ = 0;
51  READ(4)
52  d3_ = 1;
53  READ(12)
54  d0_ = 1;
55  READ(13)
56  d1_ = 1;
57  READ(15)
58  d0_ = 0;
59  READ(14)
60  d2_ = 0;
61  READ(10)
62  d0_ = 1;
63  READ(11)
64  d1_ = 0;
65  READ(9)
66  d0_ = 0;
67  READ(8)
68  d3_ = 0;
69 
70  #undef READ
71  }
72  template<typename T>
73  void copy(T & vector, uint8_t const & pos) {
74  for(uint8_t i = 0; i < 16; ++i) {
75  vector[pos + i] = in_[i].state();
76  }
77  }
78  tool::fake_button_class const & operator[](uint8_t const & pos) const {
79  return in_[pos];
80  }
81  private:
86 
88  };
89 }//end namespace device
90 
91 #endif //__CD4067_HEADER
#define READ(x)
void update()
Definition: CD4067.hpp:34
Definition: CD4067.hpp:21
tool::fake_button_class const & operator[](uint8_t const &pos) const
Definition: CD4067.hpp:78
void copy(T &vector, uint8_t const &pos)
Definition: CD4067.hpp:73
CD4067_class()
Definition: CD4067.hpp:23