본문 바로가기

Arduino

TV 리모컨으로 온도 표시 - Dot Matrix

LG TV 리모컨으로 두개의 32×8 LED 디스플레이에 온도 표시 나오게 하는 프로그램입니다.  리모컨의 숫자 클릭하면 온도가 나오고 채널목록은 삭제, 이전채널은 dot이 나옵니다.

박물관에서 리모컨으로 온도 표시를 쉽게 하고자 제작했습니다.


#include 
#include 
#include 
#include "Font_Data.h"
 
#include 
 
SoftwareSerial mySerial(3, 2); // RX, TX
int incomingByte = 0;// for incoming serial data
 
#define DEBUG 0
 
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define MAX_ZONES 2
#define ZONE_SIZE 4
#define MAX_DEVICES (MAX_ZONES * ZONE_SIZE)
#define SCROLL_SPEED  0
 
#define ZONE_UPPER  1
#define ZONE_LOWER  0
 
#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10
 
// HARDWARE SPI
MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
//MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
 
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
 
char *msg = "";
 
char *msgCheck[11] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."};
//int num[11] = {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 2};
//int intensity = 0;
 
void setup(void)
{
  // initialise the LED display
  P.begin(MAX_ZONES);
 
  // Set up zones for 2 halves of the display
  // Each zone gets a different font, making up the top
  // and bottom half of each letter
  P.setZone(ZONE_LOWER, 0, ZONE_SIZE - 1);
  P.setFont(ZONE_LOWER, BigFontLower);
 
  P.setZone(ZONE_UPPER, ZONE_SIZE, MAX_DEVICES - 1);
  P.setFont(ZONE_UPPER, BigFontUpper);
  P.setCharSpacing(P.getCharSpacing() * 1); // double height --> double spacing
  P.setIntensity(3);
 
  //  P.setZoneEffect(ZONE_UPPER, true, PA_FLIP_UD);
  //  P.setZoneEffect(ZONE_UPPER, true, PA_FLIP_LR);
 
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println(">>>Serial Starts");
 
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  Serial.println(">>>SoftwareSerial Starts");
 
}
 
void loop(void)
{
  // Run the animation and then check if BOTH zones have
  // completed. The animations are not the same length due
  // to upper/lower effects being displayed differently.
  P.displayAnimate();
 
  P.setFont(ZONE_LOWER, BigFontLower);
  P.setFont(ZONE_UPPER, BigFontUpper);
 
  P.displayZoneText(ZONE_LOWER, msg, PA_CENTER, SCROLL_SPEED, 0, PA_PRINT, PA_NO_EFFECT);
  P.displayZoneText(ZONE_UPPER, msg, PA_CENTER, SCROLL_SPEED, 0, PA_PRINT, PA_NO_EFFECT);
 
  //--------------------------------------------IR
 
  if (mySerial.available() > 0)
  {
    delay(10);
    int my_in_bytes[3] = {0, 0, 0};
 
    for (int i = 0; i <= 2; i++)
    {
      incomingByte = mySerial.read();
      my_in_bytes [i] = incomingByte;
    }
    
    int temp = int (my_in_bytes[2] - 16);
 
    
    if (temp < 11 && temp >= 0)
    {
      msg = XPortMsg(msgCheck[temp]);
    } else
    {
      msg = "";
    }
 
 
    //msg = msgCheck[temp];
    Serial.print("display msg : ");
    Serial.println(msg);
    Serial.print("display msg length : ");
    Serial.println(strlen(msg));
    Serial.print(String (my_in_bytes[0], HEX) + " ");
    Serial.print(String (my_in_bytes[1], HEX) + " ");
    Serial.println(String (my_in_bytes[2], HEX) + " ");
 
  }
 
} //---------------------------loop end
 
char* XPortMsg(char* inmsg)
  {
    char* mHeader = msg;
    // retrieve incoming string and assign to variable
    char* msgHeader = new char[strlen(inmsg)+1];
    memcpy(msgHeader,inmsg,strlen(inmsg)+1);
    msgHeader[strlen( inmsg )] = '\0';
 
    char* retVal = new char[strlen(mHeader)+strlen(msgHeader)+1];
    *retVal = '\0';
    
    // Assemble the string
    strcat(retVal,mHeader);
    strcat(retVal,msgHeader);
 
    return retVal;
  }

'Arduino' 카테고리의 다른 글

Arduino Clock – RTC  (0) 2018.12.26
Nulsom Arduino Nano  (0) 2018.12.26
Pulse Sensor LED  (0) 2018.12.26
Hardware Debounce 하드웨어 디바운스  (0) 2018.12.26
Pull-Up, Pull-Down에 대해서 알아보자  (0) 2018.12.18