LG TV 리모컨으로 두개의 32×8 LED 디스플레이에 온도 표시 나오게 하는 프로그램입니다. 리모컨의 숫자 클릭하면 온도가 나오고 채널목록은 삭제, 이전채널은 dot이 나옵니다.
박물관에서 리모컨으로 온도 표시를 쉽게 하고자 제작했습니다.
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 |
#include <MD_Parola.h> #include <MD_MAX72xx.h> #include <SPI.h> #include "Font_Data.h" #include <SoftwareSerial.h> 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; } |