-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDM_G_I2C.cpp
More file actions
250 lines (186 loc) · 6.53 KB
/
Copy pathDM_G_I2C.cpp
File metadata and controls
250 lines (186 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// ##1. 라이브러리 추가
#include "Arduino.h"
#include "DM_G_I2C.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// ##2. 초기 설정
#define OLED_RESET 4
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
Adafruit_SSD1306 display(OLED_RESET);
String ver = "1.1";
void initial_serial_print(){
Serial.println("---------------------------------------");
Serial.println("DeviceMart : http://www.devicemart.co.kr/");
Serial.println("Maker. David Gwak : myksj1105@hanmail.net");
Serial.print("DM_G_I2C.h - DeviceMart & David Gwak Copyright - library ver");
Serial.println(ver);
Serial.println("---------------------------------------");
}
void G_I2C_Scanner() {
byte error, address;
int nDevices;
initial_serial_print();
Serial.println("I2C Scanning - Waiting.");
Serial.println("---------------------------------------");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
nDevices++;
Serial.print(" : ");
Serial.print(nDevices);
Serial.println(" Device");
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done");
Serial.println("---------------------------------------");
Serial.print("In conclusion : ");
Serial.print(nDevices);
Serial.println("EA device find");
Serial.println("Thanks.");
Serial.println("---------------------------------------");
delay(5000);
}
//*************************************************************************************//
// OLED - I2C
//*************************************************************************************//
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
void OLED_Display_Image(int delay_time, unsigned char PROGMEM Data[]){
testdrawbitmap(Data, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
delay(delay_time);
}
void OLED_SETUP(){
//OLED 초기 설정
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay();
OLED_Display(2,0,0,"BodySignal"); OLED_Display_add(2,0,15,"WAITING...");
delay(1500);
}
void OLED_Display(int Fontsize,int oled_x_set,int oled_y_set, String message){
display.clearDisplay(); display.setTextColor(WHITE);
display.setTextSize(Fontsize); display.setCursor(oled_x_set,oled_y_set); display.println(message);
display.display();
}
void OLED_Display_add(int Fontsize,int oled_x_set,int oled_y_set, String message){
display.setTextColor(WHITE);
display.setTextSize(Fontsize); display.setCursor(oled_x_set,oled_y_set); display.println(message);
display.display();
}
void OLED_Display_Font2_RIGHT_up(int delaytime, String message){
display.setTextColor(WHITE); display.setTextSize(2);
for (int i=0; i < message.length(); i++){display.setCursor(12*i,0); display.println(String(message.charAt(i)));display.display(); delay(delaytime);
}}
void OLED_Display_Font2_RIGHT_do(int delaytime, String message){
display.setTextColor(WHITE); display.setTextSize(2);
for (int i=0; i < message.length(); i++){display.setCursor(12*i,15); display.println(String(message.charAt(i)));display.display(); delay(delaytime);
}}
void OLED_Display_Font2_RIGHT_with(int delaytime, String message1, String message2){
display.setTextColor(WHITE); display.setTextSize(2);
int length_size = 0;
if( message1.length() > message2.length() ){ length_size = message1.length(); }else{length_size = message2.length();}
for (int i=0; i < length_size; i++){display.setCursor(12*i,0); display.println(String(message1.charAt(i)));display.setCursor(12*i,15); display.println(String(message2.charAt(i)));display.display(); delay(delaytime);
}}
void OLED_Display_clear_white_h(){
display.clearDisplay();
for(int k=0; k < 32; k++){ for(int i=0; i < 128; i++){
display.drawPixel(i, k, 1); } display.display(); } delay(100);
}
void OLED_Display_clear_white_w(){
display.clearDisplay();
for(int i=0; i < 128; i++){ for(int k=0; k < 32; k++) {
display.drawPixel(i, k, 1); } display.display(); } delay(100);
}
void OLED_Display_clear(){
display.clearDisplay();
}
void OLED_Display_display(){
display.display();
}
void OLED_Display_clear_display(){
display.clearDisplay(); display.display();
}
void OLED_Display_dot(int x, int y, int State){
display.drawPixel(x, y, State);
}
void OLED_Display_Full_Inverse_w(){
for(int i=0; i < 128; i++){ for(int k=0; k < 32; k++) {
display.drawPixel(i, k, 2); } display.display(); } delay(100);
}
void OLED_Display_Full_Inverse_h(){
display.clearDisplay();
for(int k=0; k < 32; k++){ for(int i=0; i < 128; i++){
display.drawPixel(i, k, 2); } display.display(); } delay(100);
}
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
uint8_t icons[NUMFLAKES][3];
// initialize
for (uint8_t f=0; f< NUMFLAKES; f++) {
icons[f][XPOS] = random(display.width());
icons[f][YPOS] = 0;
icons[f][DELTAY] = random(5) + 1;
Serial.print("x: ");
Serial.print(icons[f][XPOS], DEC);
Serial.print(" y: ");
Serial.print(icons[f][YPOS], DEC);
Serial.print(" dy: ");
Serial.println(icons[f][DELTAY], DEC);
}
for(int i=0; i <10; i++){
// draw each icon
for (uint8_t f=0; f< NUMFLAKES; f++) {
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
}
display.display();
delay(200);
// then erase it + move it
for (uint8_t f=0; f< NUMFLAKES; f++) {
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
// move it
icons[f][YPOS] += icons[f][DELTAY];
// if its gone, reinit
if (icons[f][YPOS] > display.height()) {
icons[f][XPOS] = random(display.width());
icons[f][YPOS] = 0;
icons[f][DELTAY] = random(5) + 1;
}
}
}
}