1+ #include < Wire.h>
2+ #include " HT_SSD1306Wire.h"
3+
4+ #ifdef WIRELESS_STICK_V3
5+ SSD1306Wire display (0x3c , 500000 , SDA_OLED, SCL_OLED, GEOMETRY_64_32, RST_OLED); // addr , freq , i2c group , resolution , rst
6+ #else
7+ SSD1306Wire display (0x3c , 500000 , SDA_OLED, SCL_OLED, GEOMETRY_128_64, RST_OLED); // addr , freq , i2c group , resolution , rst
8+ #endif
9+
10+ void drawLines () {
11+ for (int16_t i=0 ; i<display.getWidth (); i+=4 ) {
12+ display.drawLine (0 , 0 , i, display.getHeight ()-1 );
13+ display.display ();
14+ delay (10 );
15+ }
16+ for (int16_t i=0 ; i<display.getHeight (); i+=4 ) {
17+ display.drawLine (0 , 0 , display.getWidth ()-1 , i);
18+ display.display ();
19+ delay (10 );
20+ }
21+ delay (250 );
22+
23+ display.clear ();
24+ for (int16_t i=0 ; i<display.getWidth (); i+=4 ) {
25+ display.drawLine (0 , display.getHeight ()-1 , i, 0 );
26+ display.display ();
27+ delay (10 );
28+ }
29+ for (int16_t i=display.getHeight ()-1 ; i>=0 ; i-=4 ) {
30+ display.drawLine (0 , display.getHeight ()-1 , display.getWidth ()-1 , i);
31+ display.display ();
32+ delay (10 );
33+ }
34+ delay (250 );
35+
36+ display.clear ();
37+ for (int16_t i=display.getWidth ()-1 ; i>=0 ; i-=4 ) {
38+ display.drawLine (display.getWidth ()-1 , display.getHeight ()-1 , i, 0 );
39+ display.display ();
40+ delay (10 );
41+ }
42+ for (int16_t i=display.getHeight ()-1 ; i>=0 ; i-=4 ) {
43+ display.drawLine (display.getWidth ()-1 , display.getHeight ()-1 , 0 , i);
44+ display.display ();
45+ delay (10 );
46+ }
47+ delay (250 );
48+ display.clear ();
49+ for (int16_t i=0 ; i<display.getHeight (); i+=4 ) {
50+ display.drawLine (display.getWidth ()-1 , 0 , 0 , i);
51+ display.display ();
52+ delay (10 );
53+ }
54+ for (int16_t i=0 ; i<display.getWidth (); i+=4 ) {
55+ display.drawLine (display.getWidth ()-1 , 0 , i, display.getHeight ()-1 );
56+ display.display ();
57+ delay (10 );
58+ }
59+ delay (250 );
60+ }
61+
62+ // Adapted from Adafruit_SSD1306
63+ void drawRect (void ) {
64+ for (int16_t i=0 ; i<display.getHeight ()/2 ; i+=2 ) {
65+ display.drawRect (i, i, display.getWidth ()-2 *i, display.getHeight ()-2 *i);
66+ display.display ();
67+ delay (10 );
68+ }
69+ }
70+
71+ // Adapted from Adafruit_SSD1306
72+ void fillRect (void ) {
73+ uint8_t color = 1 ;
74+ for (int16_t i=0 ; i<display.getHeight ()/2 ; i+=3 ) {
75+ display.setColor ((color % 2 == 0 ) ? BLACK : WHITE); // alternate colors
76+ display.fillRect (i, i, display.getWidth () - i*2 , display.getHeight () - i*2 );
77+ display.display ();
78+ delay (10 );
79+ color++;
80+ }
81+ // Reset back to WHITE
82+ display.setColor (WHITE);
83+ }
84+
85+ // Adapted from Adafruit_SSD1306
86+ void drawCircle (void ) {
87+ for (int16_t i=0 ; i<display.getHeight (); i+=2 ) {
88+ display.drawCircle (display.getWidth ()/2 , display.getHeight ()/2 , i);
89+ display.display ();
90+ delay (10 );
91+ }
92+ delay (1000 );
93+ display.clear ();
94+
95+ // This will draw the part of the circel in quadrant 1
96+ // Quadrants are numberd like this:
97+ // 0010 | 0001
98+ // ------|-----
99+ // 0100 | 1000
100+ //
101+ display.drawCircleQuads (display.getWidth ()/2 , display.getHeight ()/2 , display.getHeight ()/4 , 0b00000001 );
102+ display.display ();
103+ delay (200 );
104+ display.drawCircleQuads (display.getWidth ()/2 , display.getHeight ()/2 , display.getHeight ()/4 , 0b00000011 );
105+ display.display ();
106+ delay (200 );
107+ display.drawCircleQuads (display.getWidth ()/2 , display.getHeight ()/2 , display.getHeight ()/4 , 0b00000111 );
108+ display.display ();
109+ delay (200 );
110+ display.drawCircleQuads (display.getWidth ()/2 , display.getHeight ()/2 , display.getHeight ()/4 , 0b00001111 );
111+ display.display ();
112+ }
113+
114+ void printBuffer (void ) {
115+ // Initialize the log buffer
116+ // allocate memory to store 8 lines of text and 30 chars per line.
117+ display.setLogBuffer (2 , 30 );
118+
119+ // Some test data
120+ const char * test[] = {
121+ " Hello" ,
122+ " World" ,
123+ " ----" ,
124+ " Show off" ,
125+ " how" ,
126+ " the log buffer" ,
127+ " is" ,
128+ " working." ,
129+ " Even" ,
130+ " scrolling is" ,
131+ " working"
132+ };
133+
134+ for (uint8_t i = 0 ; i < 11 ; i++) {
135+ display.clear ();
136+ // Print to the screen
137+ display.println (test[i]);
138+ // Draw it to the internal screen buffer
139+ display.drawLogBuffer (0 , 0 );
140+ // Display it on the screen
141+ display.display ();
142+ delay (500 );
143+ }
144+ }
145+
146+ void VextON (void )
147+ {
148+ pinMode (Vext,OUTPUT);
149+ digitalWrite (Vext, LOW);
150+ }
151+
152+ void VextOFF (void ) // Vext default OFF
153+ {
154+ pinMode (Vext,OUTPUT);
155+ digitalWrite (Vext, HIGH);
156+ }
157+
158+ void setup () {
159+ VextON ();
160+ delay (100 );
161+
162+ display.init ();
163+ display.clear ();
164+ display.display ();
165+
166+ display.setContrast (255 );
167+
168+ drawLines ();
169+ delay (1000 );
170+ display.clear ();
171+
172+ drawRect ();
173+ delay (1000 );
174+ display.clear ();
175+
176+ fillRect ();
177+ delay (1000 );
178+ display.clear ();
179+
180+ drawCircle ();
181+ delay (1000 );
182+ display.clear ();
183+
184+ printBuffer ();
185+ delay (1000 );
186+
187+ display.setTextAlignment (TEXT_ALIGN_CENTER);
188+ display.clear ();
189+ display.display ();
190+ display.screenRotate (ANGLE_0_DEGREE);
191+ display.setFont (ArialMT_Plain_16);
192+ display.drawString (display.getWidth ()/2 , display.getHeight ()/2 -16 /2 , " ROTATE_0" );
193+ display.display ();
194+ delay (2000 );
195+
196+ display.clear ();
197+ display.display ();
198+ display.screenRotate (ANGLE_90_DEGREE);
199+ display.setFont (ArialMT_Plain_10);
200+ display.drawString (display.getWidth ()/2 , display.getHeight ()/2 -10 /2 , " ROTATE_90" );
201+ display.display ();
202+ delay (2000 );
203+
204+ display.clear ();
205+ display.display ();
206+ display.screenRotate (ANGLE_180_DEGREE);
207+ display.setFont (ArialMT_Plain_16);
208+ display.drawString (display.getWidth ()/2 , display.getHeight ()/2 -16 /2 , " ROTATE_180" );
209+ display.display ();
210+ delay (2000 );
211+
212+ display.clear ();
213+ display.display ();
214+ display.screenRotate (ANGLE_270_DEGREE);
215+ display.setFont (ArialMT_Plain_10);
216+ display.drawString (display.getWidth ()/2 , display.getHeight ()/2 -10 /2 , " ROTATE_270" );
217+ display.display ();
218+ delay (2000 );
219+
220+ }
221+
222+ void loop () { }
0 commit comments