|
| 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 | +} |
| 80 | + |
0 commit comments