|
1 | | -#include <SPI.h> |
2 | | -#include <Wire.h> |
3 | | -#include <Adafruit_GFX.h> |
4 | | -#include <Adafruit_SSD1306.h> |
5 | | -#include <SoftwareSerial.h> |
6 | | -Adafruit_SSD1306 display(4); |
7 | | -SoftwareSerial debug(11, 12); |
8 | | -int hour, minute, cpu_p, mem_p; |
9 | | - |
10 | | -char INFO[4][21]; |
11 | | -byte packet[10] = {0,}; |
12 | | - |
13 | | -void setup() { |
14 | | - // put your setup code here, to run once: |
15 | | - display.begin(SSD1306_SWITCHCAPVCC, 0x3C); |
16 | | - display.clearDisplay(); |
17 | | - display.setTextSize(1); |
18 | | - display.setTextColor(WHITE); |
19 | | - display.setCursor(0, 0); |
20 | | - display.println("resource monitor v1.0"); |
21 | | - display.setCursor(0, 8); |
22 | | - display.println(""); |
23 | | - display.setCursor(0, 16); |
24 | | - display.println("mechasolution"); |
25 | | - display.setCursor(0, 24); |
26 | | - display.println("thanks for using"); |
27 | | - display.display(); |
28 | | - pinMode(13, OUTPUT); |
29 | | - Serial.begin(115200); |
30 | | - debug.begin(9600); |
31 | | - delay(1000); |
32 | | - Serial.print('a'); |
33 | | -} |
34 | | - |
35 | | -void loop() { |
36 | | - if (Serial.available() > 9) {//입력데이터가 10개가 되면 읽어들입니다. |
37 | | - for (int i = 0; i < 10; i++) { |
38 | | - packet[i] = Serial.read();//10byte의 데이터를 읽어들입니다. |
39 | | - } |
40 | | - if ( packet[0] != 'h' |
41 | | - && packet[2] != 'm' |
42 | | - && packet[4] != 'C' |
43 | | - && packet[6] != 'M' |
44 | | - && packet[8] != 'D') {//포멧이 올바르게 왔는지 확인 |
45 | | - //data format error |
46 | | - digitalWrite(13, HIGH); |
47 | | - delay(50); |
48 | | - digitalWrite(13, LOW); |
49 | | - delay(50); |
50 | | - digitalWrite(13, HIGH); |
51 | | - delay(50); |
52 | | - digitalWrite(13, LOW); |
53 | | - //포멧이 올바르지 않으면, 에러 출력 |
54 | | - while (Serial.available() > 0 && Serial.read()); |
55 | | - //시리얼 버퍼 초기화 |
56 | | - return;//루프문 종료 |
57 | | - } |
58 | | - //데이터가 올바르게 오면 한번 깜빡임 |
59 | | - digitalWrite(13, HIGH); |
60 | | - delay(50); |
61 | | - digitalWrite(13, LOW); |
62 | | - //화면 출력 데이터 수정 |
63 | | - sprintf(INFO[0], " %02d:%02d", (int)packet[1], (int)packet[3]); |
64 | | - sprintf(INFO[1], "CPU : %3d%%", (int)packet[5]); |
65 | | - sprintf(INFO[2], "RAM : %3d%%", (int)packet[7]); |
66 | | - sprintf(INFO[3], "DISK : %3d%%", (int)packet[9]); |
67 | | - display.clearDisplay();//디스플레이 초기화 |
68 | | - display.setCursor(0, 0); |
69 | | - display.println(INFO[0]); |
70 | | - display.setCursor(0, 8); |
71 | | - display.println(INFO[1]); |
72 | | - display.setCursor(0, 16); |
73 | | - display.println(INFO[2]); |
74 | | - display.setCursor(0, 24); |
75 | | - display.println(INFO[3]); |
76 | | - //화면 출력 데이터들을 실제로 출력합니다. |
77 | | - display.display(); |
78 | | - } |
79 | | -} |
| 1 | +#include <SPI.h> |
| 2 | +#include <Wire.h> |
| 3 | +#include <Adafruit_GFX.h> |
| 4 | +#include <Adafruit_SSD1306.h> |
| 5 | +#include <SoftwareSerial.h> |
| 6 | +Adafruit_SSD1306 display(4); |
| 7 | +SoftwareSerial debug(11, 12); |
| 8 | +int hour, minute, cpu_p, mem_p; |
| 9 | + |
| 10 | +char INFO[4][21]; |
| 11 | +byte packet[10] = {0,}; |
| 12 | + |
| 13 | +void setup() { |
| 14 | + display.begin(SSD1306_SWITCHCAPVCC, 0x3C); |
| 15 | + display.clearDisplay(); |
| 16 | + display.setTextSize(1); |
| 17 | + display.setTextColor(WHITE); |
| 18 | + display.setCursor(0, 0); |
| 19 | + display.println("resource monitor v1.0"); |
| 20 | + display.setCursor(0, 8); |
| 21 | + display.println(""); |
| 22 | + display.setCursor(0, 16); |
| 23 | + display.println("mechasolution"); |
| 24 | + display.setCursor(0, 24); |
| 25 | + display.println("thanks for using"); |
| 26 | + display.display(); |
| 27 | + pinMode(13, OUTPUT); |
| 28 | + Serial.begin(115200); |
| 29 | + debug.begin(9600); |
| 30 | + delay(1000); |
| 31 | + Serial.print('a'); |
| 32 | +} |
| 33 | + |
| 34 | +void loop() { |
| 35 | + if (Serial.available() > 9) {//입력데이터가 10개가 되면 읽어들입니다. |
| 36 | + for (int i = 0; i < 10; i++) { |
| 37 | + packet[i] = Serial.read();//10byte의 데이터를 읽어들입니다. |
| 38 | + } |
| 39 | + if ( packet[0] != 'h' |
| 40 | + && packet[2] != 'm' |
| 41 | + && packet[4] != 'C' |
| 42 | + && packet[6] != 'M' |
| 43 | + && packet[8] != 'D') {//포멧이 올바르게 왔는지 확인 |
| 44 | + //data format error |
| 45 | + digitalWrite(13, HIGH); |
| 46 | + delay(50); |
| 47 | + digitalWrite(13, LOW); |
| 48 | + delay(50); |
| 49 | + digitalWrite(13, HIGH); |
| 50 | + delay(50); |
| 51 | + digitalWrite(13, LOW); |
| 52 | + //포멧이 올바르지 않으면, 에러 출력 |
| 53 | + while (Serial.available() > 0 && Serial.read()); |
| 54 | + //시리얼 버퍼 초기화 |
| 55 | + return;//루프문 종료 |
| 56 | + } |
| 57 | + //데이터가 올바르게 오면 한번 깜빡임 |
| 58 | + digitalWrite(13, HIGH); |
| 59 | + delay(50); |
| 60 | + digitalWrite(13, LOW); |
| 61 | + //화면 출력 데이터 수정 |
| 62 | + sprintf(INFO[0], " %02d:%02d", (int)packet[1], (int)packet[3]); |
| 63 | + sprintf(INFO[1], "CPU : %3d%%", (int)packet[5]); |
| 64 | + sprintf(INFO[2], "RAM : %3d%%", (int)packet[7]); |
| 65 | + sprintf(INFO[3], "DISK : %3d%%", (int)packet[9]); |
| 66 | + display.clearDisplay();//디스플레이 초기화 |
| 67 | + display.setCursor(0, 0); |
| 68 | + display.println(INFO[0]); |
| 69 | + display.setCursor(0, 8); |
| 70 | + display.println(INFO[1]); |
| 71 | + display.setCursor(0, 16); |
| 72 | + display.println(INFO[2]); |
| 73 | + display.setCursor(0, 24); |
| 74 | + display.println(INFO[3]); |
| 75 | + //화면 출력 데이터들을 실제로 출력합니다. |
| 76 | + display.display(); |
| 77 | + } |
| 78 | +} |
80 | 79 |
|
0 commit comments