PololuOLED library
PololuSH1106.h
Go to the documentation of this file.
1 // Copyright (C) Pololu Corporation. See www.pololu.com for details.
2 
4 
5 #pragma once
6 
7 #include "PololuSH1106Main.h"
8 
21 {
22 public:
29  void setPins(uint8_t clk, uint8_t mos, uint8_t res = 255, uint8_t dc = 255,
30  uint8_t cs = 255)
31  {
32  clkPin = clk;
33  mosPin = mos;
34  resPin = res;
35  dcPin = dc;
36  csPin = cs;
37  }
38 
42  void initPins()
43  {
44  if (resPin != 255) { pinMode(resPin, OUTPUT); }
45  pinMode(clkPin, OUTPUT);
46  digitalWrite(clkPin, LOW);
47  pinMode(mosPin, OUTPUT);
48  if (dcPin != 255) { pinMode(dcPin, OUTPUT); }
49  if (csPin != 255) { pinMode(csPin, OUTPUT); }
50  }
51 
53  void reset()
54  {
55  if (resPin == 255) { return; }
56  digitalWrite(resPin, LOW);
57  delayMicroseconds(10);
58  digitalWrite(resPin, HIGH);
59  delayMicroseconds(10);
60  }
61 
69  {
70  pinMode(clkPin, OUTPUT);
71  digitalWrite(clkPin, LOW);
72  pinMode(mosPin, OUTPUT);
73  if (csPin != 255) { digitalWrite(csPin, LOW); }
74  }
75 
79  {
80  if (csPin != 255) { digitalWrite(csPin, HIGH); }
81  }
82 
86  {
87  dataMode = 0;
88  if (dcPin != 255) { digitalWrite(dcPin, LOW); }
89  }
90 
94  {
95  dataMode = 1;
96  if (dcPin != 255) { digitalWrite(dcPin, HIGH); }
97  }
98 
101  void sh1106Write(uint8_t d)
102  {
103  if (dcPin == 255)
104  {
105  digitalWrite(clkPin, LOW);
106  digitalWrite(mosPin, dataMode);
107  digitalWrite(clkPin, HIGH);
108  }
109 
110  digitalWrite(clkPin, LOW);
111  digitalWrite(mosPin, d >> 7 & 1);
112  digitalWrite(clkPin, HIGH);
113 
114  digitalWrite(clkPin, LOW);
115  digitalWrite(mosPin, d >> 6 & 1);
116  digitalWrite(clkPin, HIGH);
117 
118  digitalWrite(clkPin, LOW);
119  digitalWrite(mosPin, d >> 5 & 1);
120  digitalWrite(clkPin, HIGH);
121 
122  digitalWrite(clkPin, LOW);
123  digitalWrite(mosPin, d >> 4 & 1);
124  digitalWrite(clkPin, HIGH);
125 
126  digitalWrite(clkPin, LOW);
127  digitalWrite(mosPin, d >> 3 & 1);
128  digitalWrite(clkPin, HIGH);
129 
130  digitalWrite(clkPin, LOW);
131  digitalWrite(mosPin, d >> 2 & 1);
132  digitalWrite(clkPin, HIGH);
133 
134  digitalWrite(clkPin, LOW);
135  digitalWrite(mosPin, d >> 1 & 1);
136  digitalWrite(clkPin, HIGH);
137 
138  digitalWrite(clkPin, LOW);
139  digitalWrite(mosPin, d >> 0 & 1);
140  digitalWrite(clkPin, HIGH);
141  }
142 
143 private:
144  uint8_t clkPin = 13, mosPin = 13, resPin = 255, dcPin = 255, csPin = 255;
145  bool dataMode;
146 };
147 
149 class PololuSH1106 : public PololuSH1106Main<PololuSH1106Core>
150 {
151 public:
170  PololuSH1106(uint8_t clk, uint8_t mos, uint8_t res = 255, uint8_t dc = 255,
171  uint8_t cs = 255)
172  {
173  core.setPins(clk, mos, res, dc, cs);
174  }
175 };
SH1106 core class implemented using Arduino I/O functions.
Definition: PololuSH1106.h:21
void sh1106TransferEnd()
This function is called by PololuSH1106Main to end a data transfer to the SH1106.
Definition: PololuSH1106.h:78
void sh1106DataMode()
This function is called by PololuSH1106Main to indicate that the bytes it is about to pass to sh1106W...
Definition: PololuSH1106.h:93
void sh1106CommandMode()
This function is called by PololuSH1106Main to indicate that the bytes it is about to pass to sh1106W...
Definition: PololuSH1106.h:85
void setPins(uint8_t clk, uint8_t mos, uint8_t res=255, uint8_t dc=255, uint8_t cs=255)
Configures what pins this class will use.
Definition: PololuSH1106.h:29
void initPins()
This function is called by PololuSH1106Main to perform any initializations that might be needed for t...
Definition: PololuSH1106.h:42
void sh1106TransferStart()
This function is called by PololuSH1106Main to start a data transfer to the SH1106.
Definition: PololuSH1106.h:68
void sh1106Write(uint8_t d)
This function is called by PololuSH1106Main to write commands or data to the SH1106.
Definition: PololuSH1106.h:101
void reset()
This function is called by PololuSH1106Main to reset the SH1106.
Definition: PololuSH1106.h:53
Generic SH1106 class implemented using Arduino I/O functions.
Definition: PololuSH1106.h:150
PololuSH1106(uint8_t clk, uint8_t mos, uint8_t res=255, uint8_t dc=255, uint8_t cs=255)
Creates a new instance of PololuSH1106.
Definition: PololuSH1106.h:170
This class makes it easy to display text and graphics on a 128x64 SH1106 OLED.
PololuSH1106Core core
This object handles all low-level communication with the SH1106.