1. MiniCom
- SimpleTimer, 16x2 LCD의 간편 사용을 위한 클래스
#pragam once
#include<Arduino.h>
#include<LiquidCrystal_I2C.h>
#include<SimpleTimer.h>
class MiniCom{
long serial_bps;
LiquidCrystal_I2C lcd;
SimpleTimer timer;
bool no_lcd;
public:
MiniCom(long serial_bps = 115200, int lcd_addr = 0x27);
void setNoLcd() {no_lcd = true;};
void init();
void run();
int setInterval(unsigned long interval, timer_callback f);
SimpleTimer& getTimer() {return timer; }
void print(int row, const char *pMsg);
void print(int row, String title, int value);
void print(int row, String title1, int value1, String title2, int value2);
void print(int row, String title, double value);
void print(int row, String tilte1, double value1,
String title2, double value2);
};
#include "MiniCom.h"
MiniCom::MiniCom(long serial_bps, int lcd_addr)
:serial_bps(serial_bps), lcd(lcd_addr, 16, 2){
no_lcd = false;
}
void MiniCom::init(){
Serial.begin(serial_bps);
if(!no_lcd){
lcd.init();
lcd.backlight();
}
}
int MiniCom::setInterval(unsigned long interval, timer_callback f)
return timer.setInterval(interval, f);
}
void MiniCom::run(){
timer.run();
}
void MiniCom::print(int row, const char *pMsg) {
if(no_lcd) return;
char buf[17];
sprintf(buf, "%-16s", pMsg);
lcd.setCursor(0, row);
lcd.print(buf);
}
void MiniCom::print(int row, String title, int value) {
if(no_lcd) return;
String buf = title + value;
print(row, buf.c_str());
}
void MiniCom::print(int row, String title1, int value1,
String title2, int value2) {
if(no_lcd) return;
String buf = title1 + value1 + "," + title2 + value2;
print(row, buf.c_str());
}
void MiniCom::print(int row, String title, double value) {
if(no_lcd) return;
String buf = title + value;
print(row, buf.c_str());
}
void MiniCom::print(int row, String title1, double value1,
String title2, double value2) {
if(no_lcd) return;
String buf = title1 + value1 + "," + title2 + value2;
print(row, buf.c_str());
}
#include "MiniCom.h"
#include <Led.h>
Led led(8);
MiniCom com;
void setup(){
com.init();
com.print(0, "[[MiniCom]]");
com.setInterval(1000, check);
}
void loop(){
com.run();
}
void check(){
int on = led.toggle();
if(on){
com.print(1,"led on");
}
else{
com.print(1, "led off");
}
}