macsbug

Just another WordPress.com site

32ch Logic Analyzer of MEGA TFT35 TOUCH

leave a comment »

32bit ( Arinc 429 ) シリアルデーターを、TFT3.5インチ(480×320) ディスプレーに表示する。

タッチ操作で、任意のラベル設定、1bitを選択(色)、”0” 叉は ”1” 設定でワーニング(音)、表示の開始及び停止ができる。

Hard Ware :
1. Arinc429 Receiver
2. Arduino MEGA
3. LCD module TFT3.5inch TFT LCD screen ( aitendo or AliExpress )

Function:
1. 32ch Logic Analyzer
2. Monitor LABEL Input
3. Monitor BIT Input
4. 0/1 Bit Monitor Input ( Warning Output )

Display Sample :

32ch Logic Analyzer                                                               LABEL input of Touch

317315

 

 

 

 

 

 

ハードウエアー・メモ

1.  Arduino MEGAのCPU Clockは、16MHzで、やや低速である。ただし、Arinc 429 の速度には対応可能。

2.  3.5 inch TFT LCD Touch Screen Display Moduleの解像度は、480×320であり、縦の表示能力は、24ch分である。

3.  3.5 inch TFT LCD Touch Screen Display Moduleは、Aitendo 及び AliExpress で販売(2013,2014年)しているが、設計ミスが2つある。ピンに半ピッチずれがある事。タッチが動作しない事(J3配線の一部をカットする必要がある。注:Flex wire Solder)。(設計ミスの製品が販売されている)

318

 

 

 

 

 

 

SDカードの CS と タッチパネルの X+ がショート。Short -> * で表示。  追記:2015.03.07
SD: SD-2—RP4-*-53(CS)
TP: J3-1-*-U3-2(X+)

他の配線:
TP: IC=XPT2046
J3-1—U3-2(X+)
J3-2—U3-3(Y+)
J3-3—U3-4(X-)
J3-4—U3-5(Y-)
U3-11–RP11—A5(NA)
U3-12–RP11—A4(OUT)
U3-13–RP10—A0(BUSY)
U3-14–RP10—A3(IN)
U3-15–RP10—A2(CS)
U3-16–RP10—A1(CLK)

SD:
SD-2—RP4—53(CS)
SD-3—RP4—51(IN)
SD-5—RP4—52(CLK)
SD-7—RP4—50(OUT)

LCD:
CS–RP3—40
RS–RP3—38
WR–RP7—39
RD–R2—-3V3
RST–RP7—41
D0~D7–RP1,2,3,5,6,7–37~30
D8~D15–RP1,2,3,5,6,7–22~29

4.  ebay で販売している、3.5″ TFT LCD Touch Screen Display Moduleは、アダプター基盤が必要である。その為、高さが増す。

 

ソフトウエアー・メモ

1.  MEGAのCPU CLOCKは、16MHzで、1マシンサイクルは、62.5 nsecである。

2.  MEGAの配線上、UNOのように高速I/O操作(1命令)はできない。ポートのマスク命令は全てのポートに適応してしまう為、使用できない、その為に2つのビット(429A,429B)を別々に読む必要がある。例:ax = PINH & _BV(6) + _BV(5); 、、これが最速の方法である。

3.  TFTの表示には、UTFT   Libraryを使用した。

4.  TFTのTouchは、UTouch Libraryを使用した。

5.  TFTのTouchは、Calibration(UTouch Calibration Data Verification)が必要である。

6.  Touch にチャタリングが若干あり、防止策が必要である。

7.  32bitと次の32bitの間が短い場合は、MEGAの信号処理に時間がかかる為に次の32bitが取り込めない場合がある。対策として連続で来る事を前提に連続して読み込む方法がある。今回のソフトは未対応である。例:LABEL 164,165。LABEL255,255,,,255。

8.  Arinc 32bit信号用であるが、ch数を変える事により他のデジタル信号も表示可能である。

スケッチ
//=========================================================================
// 32ch Logic Analyzer for Arduino MEGA
//=========================================================================
// ORG    2013.12.30  32bit ARM Cortex-M3 CPU + TFT + Touch          s.ono
// REV 1  2014.01.01  mode 5        : Maintenance Mode
// REV 2  2014.01.01  mode 6        : Monitor Mode
// REV 3  2014.01.01  MON,BIT       : digitalWrite
// REV 4  2014.01.03  I/O PORT      : digitalWrite(13)
// REV 5  2014.01.10  Receiver      : 8,9 INPUT
// REV 6  2014.01.12  Receiver      : Void LOOP AREA, RE PROGRAMING
// REV 7  2014.01.12  I/O Hi Speed  : DirectPort
// REV 8  2014.01.13  LABEL,MONITOR : LABEL LOCK, Warning
// REV 9  2014.01.16  Null check    : 80nsec null check
// REV 10 2014.01.25  I/O DirectPort: MEGA VERSION
// REV 11 2014.01.30  Parity Check  : ODD/ENE
//-------------------------------------------------------------------------
// ARINC 429    : 1 Word 32 bit                       : 2.54  msec
// ARINC 429    : 1 cycle                             :  80   usec         
//-------------------------------------------------------------------------
// Arduino DUE  : Atmel SAM3X8E ARM Cortex-M3 CPU     : 32bit 84MHz
// Arduino DUE  : 1 cpu clock cycle : 1sec/84MHz      :  11.9 nsec
// Arduino MEGA : 1 cpu clock cycle : 1sec/16MHz      :  62.5 nsec
//-------------------------------------------------------------------------
// Arduino MEGA : digitalWrite   : 44 CPU CLOCK CYCLE : 2.750 msec
// Arduino MEGA : PORTH _BV(PHx) :  3 CPU CLOCK CYCLE : 187.5 nsec
// Arduino MEGA : PINH & _BV(6)  :  3 CPU CLOCK CYCLE : 187.5 nsec
// Arduino DUE  : digitalWrite   : 44 CPU CLOCK CYCLE : 523.6 nsec
// Arduino DUE  : digitalRead    : 30 CPU CLOCK CYCLE : 357.1 nsec
// Arduino DUE  : DirectPort Read: 26 CPU CLOCK CYCLE : 307.7 nsec
//-------------------------------------------------------------------------
// UNO,MEGA :
// if(bit_is_set(PIND,PIND2)){PORTB=_BV(1)|_BV(2);// D2=HIGH->D9,D10 HIGH
// }else{ PORTB &= ~_BV(1) & ~_BV(2);}        // D2 not HIGH->D9,D10 LOW
// DUE :
// if ( digitalRead(2) == HIGH){ digitalWrite(13,HIGH);}
// Arduino DUE   : Port manipulation PINx commands with Arduino Due
//                 http://forum.arduino.cc/index.php?topic=129868.15
//-------------------------------------------------------------------------
// Arduino MEGA 2560 (16MHz) : Arduino 1.0.5, 1.5.5
// Arduino Due       (84MHz) : Arduino 1.5.2
//-------------------------------------------------------------------------
// 3.5" 480x320 TFT LCD Module, Controller : R61581
// UTFT   Library: http://henningkarlsen.com/electronics/library.php?id=51
// UTouch Library: http://henningkarlsen.com/electronics/library.php?id=55
// UTouch Calibration Data Verification
//               : http://henningkarlsen.com/electronics/t_cal_verify.php
//=========================================================================
// mode 0 : Free RUN  : RECEIVER, LED DISP, DRAW DISP
// mode 1 : PAUSE     : PAUSE ON/OFF
// mode 2 :           :
// mode 3 : LABEL     : 000 to 777
// mode 4 : BIT       : BIT 9 to 32
// mode 5 : DEBUG     : Mode,x pos,LABEL,BIT,MON BIT Display
// mode 6 : MONITOR   : BIT ( 0/1 ) WARNING : OUTPUT Pin 13
//=========================================================================
// Binary sketch size: 46,398 bytes (of a 258,048 byte maximum) - 17% used
//=========================================================================
#include <UTFT.h>                                // UTFT   Routine
#include <UTouch.h>                              // UTouch Routine
extern uint8_t SmallFont[];                      // Small Font
extern uint8_t BigFont[];                        // Big   Font
extern uint8_t SevenSegNumFont[];                // SevenSegNumFont
UTFT   myGLCD(CTE35IPS,38,39,40,41);             // TFT set,Model=CTE35IPS
UTouch myTouch(6,5,4,3,2);                       // Touch setup
//-----------------------------------------------// Receiver
int const RA = 9;                                // 429A input port
int const RB = 8;                                // 429B input port
String n = "00000000000000000000000000000000";   // nul data
String b = "00000000000000000000000000000000";   // Receiver 32bit
String c = "00000000000000000000000000000000";   // 32bit buffer
int ax;                                          // Read 429A data
int bx;                                          // Read 429B data
String LB  = "000";                              // Rx  LABEL
//-----------------------------------------------// Display
String z;                                        // BIT
String m;                                        // MONITOR
int d = 5;                                       // x division
int H;                                           // Hi Level
int L;                                           // Lo Level
int x1 =  60;                                    // Analyzer x start pos
int bk = 200;                                    // background color R.G.B
int L1,L2,L3;                                    // Label data
char r[3];                                       //
int s;                                           // SELECT bit
int pa;                                          // Parity check
String parity;                                   // Parity ODD/ENE
//-----------------------------------------------// Touch
int mode = 0;                                    // Loop mode:0,1,2,3,4,5,6
String LBL = "000";                              // KEY LABEL
String BIT = "0";                                // BIT
String MON = "1";                                // MONITOR bit
//=========================================================================
void setup() {                                   //
 //Serial.begin(115200);
 pinMode( 8, INPUT);                             // 429B
 pinMode( 9, INPUT);                             // 429A
 pinMode(10, INPUT);                             // Control
 pinMode(13, OUTPUT);                            // LED 13 OUTPUT
 digitalWrite(13,LOW);                           // Pin 13 LOW
 //----------------------------------------------//
 myGLCD.InitLCD();                               // LCD Initialize
 myGLCD.setFont(SmallFont);                      // Font : smallfont
 myGLCD.clrScr();                                // LCS Clear
 myTouch.InitTouch();                            // Touch Initialize
 myTouch.setPrecision(PREC_EXTREME);             // Touch Sence MAX
 myGLCD.setColor(bk,bk,bk);                      // panel background color
 myGLCD.fillRect(0, 0, 480, 320);                // panel all fill
 myGLCD.setColor(0, 0, 0);                       // moji color=white
 myGLCD.setBackColor(bk,bk,bk);                  // moji background color
 myGLCD.print(" 32ch LOGIC ANALYZER", LEFT, 1);  // TITLE
 //----------------------------------------------//
 myGLCD.setColor(0, 0, 0);                       // 1/0 info
 myGLCD.print("10",29, 13);                      // 1/0 info
 myGLCD.setColor(0,0,0);                         // 1/0 waku
 myGLCD.fillRect(27, 27, 44, 34);                // 1/0 waku
 myGLCD.setColor(255,255,255);                   // 1/0 waku kage
 myGLCD.drawLine(27, 35, 45, 35);                // 1/0 waku kage
 myGLCD.drawLine(45, 35, 45, 27);                // 1/0 waku kage
 myGLCD.setColor(127, 0, 255);                   // 1   color
 myGLCD.fillRect(28, 28, 34, 33);                // 1   fill
 myGLCD.setColor(0, 165, 255);                   // 0   color
 myGLCD.fillRect(36, 28, 43, 33);                // 0   fill
 //----------------------------------------------//
 for (int x=1; x<9; x++){                        // LED 1-8 bit NO
   myGLCD.setColor(0, 0, 0);                     // LED 1-8 bit NO
   myGLCD.printNumI(x, (x*22)+33, 13);           // LED 1-8 bit NO
 }                                               // LED 1-8 bit NO
 myGLCD.print("LABEL", 230, 13);                 // LED "LABEL"
 //----------------------------------------------//
 String bn;                                      // LED 9-32 bit NO
 for (int y=9; y<33; y++){                       // LED 9-32 bit NO
   myGLCD.setColor(0, 0, 0);                     // LED 9-32 bit NO
   bn = " " + String(y);                         // LED 9-32 bit NO
   if (y < 10) { bn = "  "+String(y);}           // LED 9-32 bit NO
   myGLCD.print(bn, LEFT, (y-5)*11);             // LED 9-32 bit NO
 }                                               // LED 9-32 bit NO
  //---------------------------------------------//
  for (int x=50; x<220; x+=22){                  // LED waku 1-8
    myGLCD.setColor(0,0,0);                      // LED waku 1-8
    myGLCD.fillRect(x, 27, x+14, 34);            // LED waku 1-8
    myGLCD.setColor(255,255,255);                // LED waku 1-8 kage
    myGLCD.drawLine(x, 35, x+15, 35);            // LED waku 1-8 kage
    myGLCD.drawLine(x+15, 35, x+15, 27);         // LED waku 1-8 kage
  }                                              // LED waku 1-8 kage
  //---------------------------------------------//
  for (int y=46; y<300; y+=11){                  // LED waku 9-32
    myGLCD.setColor(0,0,0);                      // LED waku 9-32
    myGLCD.fillRect(27, y, 44, y+7);             // LED waku 9-32
    myGLCD.setColor(255,255,255);                // LED waku 9-32 kage
    myGLCD.drawLine(27, y+8, 45, y+8);           // LED waku 9-32 kage
    myGLCD.drawLine(45, y, 45, y+8);             // LED waku 9-32 kage
    myGLCD.drawLine(27, y+9, 46, y+9);           // LED waku 9-32 kage
    myGLCD.drawLine(46, y, 46, y+9);             // LED waku 9-32 kage
  }                                              // LED waku 9-32 kage
  //---------------------------------------------//
  myGLCD.setColor(0,0,0);                        // LA WAKU WHITE kage
  myGLCD.drawRect(49, 39, 471, 315);             // LA WAKU WHITE kage
  myGLCD.setColor(255,255,255);                  // LA WAKU kage
  myGLCD.drawLine(49, 316, 472, 316);            // LA WAKU kage
  myGLCD.drawLine(472, 316, 472, 39);            // LA WAKU kage
  //---------------------------------------------//
  myGLCD.setColor(255,255,255);                  // LA BACK GROUND
  myGLCD.fillRect(50, 40, 470, 314);             // LA BACK GROUND
  //---------------------------------------------//
  myGLCD.setColor(0,0,0);                        // SW "LABEL"
  myGLCD.drawRect(300,5,350,35);                 // SW "LABEL"
  myGLCD.print("LABEL",307,15);                  // SW "LABEL"
  myGLCD.setColor(255,255,255);                  // SW "LABEL" kage
  myGLCD.drawLine(300, 36, 351, 36);             // SW "LABEL" kage
  myGLCD.drawLine(351, 36, 351, 5);              // SW "LABEL" kage
  //---------------------------------------------//
  myGLCD.setColor(0,0,0);                        // SW "BIT"
  myGLCD.drawRect(360,5,410,35);                 // SW "BIT"
  myGLCD.print("BIT",375,15);                    // SW "BIT"
  myGLCD.setColor(255,255,255);                  // SW "BIT" kage
  myGLCD.drawLine(360, 36, 411, 36);             // SW "BIT" kage
  myGLCD.drawLine(411, 36, 411, 5);              // SW "BIT" kage
  //---------------------------------------------//
  myGLCD.setColor(0,0,0);                        // SW "MON"
  myGLCD.drawRect(420,5,470,35);                 // SW "MON"
  myGLCD.print("MON",435,15);                    // SW "MON"
  myGLCD.setColor(255,255,255);                  // SW "MON" kage
  myGLCD.drawLine(420, 36, 471, 36);             // SW "MON" kage
  myGLCD.drawLine(471, 36, 471, 5);              // SW "MON" kage
  //---------------------------------------------//
  for ( int i = 0; i < 10540; i++ ){             // 2.54msec null check
    ax = PINH & _BV(6) + _BV(5);                 //
   if ( ax > 0 ){ i = 0  ;}                      //
  }                                              //
  //---------------------------------------------//
}
//===============================================//=======================
void loop() {                                    //
 while (myTouch.dataAvailable() == true) {       // interupt Touch
   mode = touch(mode,x1);                        // MODE READ
   if (mode> 10 && mode<120){mode =  key(mode);} // key action
   if (mode>120 && mode<320){mode = bkey(mode);} // bit key action
   if (mode>320            ){mode = mkey(mode);} // mon key action
   delay(150);                                   //
 }                                               //
  //---------------------------------------------// --------------------
 /*
 if (mode==2 | mode==3 | mode==4 | mode==5){     // Maintenance Mode  
  myGLCD.setFont(SevenSegNumFont);               // font
  myGLCD.setColor(255,0,0);                      // color
  myGLCD.printNumI(mode,80,60);                  // mode
  myGLCD.printNumI(x1,80,120);                   // x position
  myGLCD.print(LBL,80,180);                      // LABEL
  myGLCD.print(BIT,80,240);                      // BIT
  myGLCD.print(MON,180,240);                     // MON
 }                                               //
 */
 //----------------------------------------------// --------------------
 //if ( mode == 0 | mode == 5 ){ goto rx;}       // -> Receiver
 if ( mode > 0 ){ goto pass;}                    // -> Pass
 //goto pass;                                    // Pass
 rx: //------------------------------------------//---------------------
 // 32 bit Reciver                               // mode = 0,5 only
 //----------------------------------------------// --------------------
 for ( int i = 0; i < 166; i++ ){                // 80 usec null check
    ax = PINH & _BV(6) + _BV(5);                 // 166:min 130
    if ( ax > 0){ i = 0 ;}                       //
 }                                               //
 //----------------------------------------------// --------------------
 b = n;                                          // null set
 for ( int i=0; i<32; i++ ){                     // 32 bit
 p1: ax = PINH & _BV(6) + _BV(5);                // 429A READ
     if ( ax == 0 ){ goto p1;}                   // null loop
     if ( ax == 64 ){ b[i] = '1';                // 429A 1 store
 p2: ax = PINH & _BV(6); if (ax == 64){goto p2;} // 429A H Level ck
     goto p4;                                    //
     }                                           //
 p3: bx = PINH & _BV(5); if (bx == 32){goto p3;} // 429B H Level ck
 p4:;                                            // next bit
  }                                              //
  //---------------------------------------------// --------------------
  pa = b[0];                                     //
  for ( int i=1; i<32; i=i++){ pa = pa ^ b[i];}  //
  if ( pa == 1 ){ parity = "ODD";}               // odd parity (1)
  if ( pa == 0 ){ parity = "EVE";}               // eve parity (0)
  //---------------------------------------------// --------------------
  L1 = 2*b[0] + b[1] - 144;                      // Label 1
  L2 = 4*b[2] + 2*b[3] + b[4] - 336;             // Label 2
  L3 = 4*b[5] + 2*b[6] + b[7] - 336;             // Label 3
  LB = String(L1) + String(L2) + String(L3);     // bit to String
  //---------------------------------------------// --------------------
  if ( LBL.equals(LB))   { goto disp;}           // LBL Select
  if ( LBL.equals("000")){ goto disp;}           // LBL 000 ALL mode
  goto pass;                                     // display pass
 disp: // 32 bit display-------------------------//---------------------
  myGLCD.setColor(255,255,255);                  // color black
  myGLCD.fillRect(x1,40,x1+d,314);               // Draw Clear bar
  //---------------------------------------------// --------------------
  myGLCD.setColor(0,0,0);                        // LABEL color white
  myGLCD.print( LB, 230, 24);                    // LABEL PRINT
  myGLCD.print( parity, 263, 24);                // parity disp
  //---------------------------------------------// --------------------
  for ( int i=0; i<8; i++ ){                     // 32bit=(0)1-(7)8      
    if (b[i] == '1'){myGLCD.setColor(127,0,255);}// LED color green '1'
    if (b[i] == '0'){myGLCD.setColor(0,165,255);}// LED color orange
    myGLCD.fillRect((i*22)+51,28,(i*22)+63,33);  // LED bit fill
  }                                              // end of 0 to 7 bit
  //---------------------------------------------// --------------------
  for ( int i=8; i<32; i++ ){                    // 32bit=(8)9-(31)32
    if (b[i] == '1'){myGLCD.setColor(127,0,255);}// LED color green '1'
    if (b[i] == '0'){myGLCD.setColor(0,165,255);}// LED color orange
    H = 11*i - 41; L = 11*i - 36;                // LA H/L POS
    myGLCD.fillRect(28,H,43,L);                  // LED bit fill
    //-------------------------------------------// --------------------
    myGLCD.setColor(0,0,0);                      // LA bit color white
    BIT.toCharArray(r,3); s = atoi(r) - 1;       // String -> cha -> val
    if ( s == i ){                               // SELECT BIT
     myGLCD.setColor(0,255,0);                   // LA Monitor color RED
     if(MON.equals(String(b[i]))){               //
            PORTB |= _BV(5);}                    // LED 13 ON
     else{  PORTB &= ~_BV(5);}                   // LED 13 OFF
    }                                            // end of select bit
    //-------------------------------------------// --------------------
    if (b[i]!=c[i]){myGLCD.drawLine(x1,L,x1,H);} // LA bit CG V-line
    if (b[i]=='0'){myGLCD.drawLine(x1,L,x1+d,L);}// LA bit 0 level LO
    if (b[i]=='1'){myGLCD.drawLine(x1,H,x1+d,H);}// LA bit 1 level HI
    //-------------------------------------------// --------------------  
    c[i] = b[i];                                 // store bit "0/1"
  }                                              // end of to 32 bit
  x1 = x1 + d;                                   // x inc
  if ( x1 > 460 ){ x1 = 60;}                     // x pos max,start
 pass:;                                          //
}                                                // end of loop
//===============================================//========================
// Touch Routine                                 //
//=========================================================================
int touch(int mode, int x1){                     // Touch
  long xt, yt;                                   // a,y position
  myTouch.read();                                // TOUCH READ
  xt = myTouch.getX();                           // X TOUCH
  yt = myTouch.getY();                           // Y TOUCH
  /*
  // MAINTENANCE ---------------------------------------------------------
  if ( xt>0 & xt<50 & yt>0 & yt<50){             // DEBUG MODE AREA
    if ( mode == 0 ){ mode = 5; goto p2;}        //
    if ( mode == 5 ){ mode = 0; goto p2;}        //
  }                                              //
  p2:                                            //
  */
  // PAUSE ---------------------------------------------------------------
  if ( xt>50 & xt<290 & yt>40 & yt<314){         // PAUSE MODE AREA
    if ( mode == 0 ){                            //
      mode = 1;                                  // MODE 1
      myGLCD.setColor(255,200,200);              // Draw bit Clear
      myGLCD.fillRect(x1,40,x1+5,314);           // Draw bit Clear
      delay(50);                                 // WAIT
    }                                            //
    else{mode = 0;delay(50);}                    // MODE 0, FREE RUN, WAIT
  }                                              //
  //---------------------------------------------//
  if ( mode == 3 ){                              // LABEL
   int k;                                        //
   //     x1       x2       y1       y2          // LABEL KYE AREA
   if (xt>305 & xt<355 & yt>100 & yt<150){k=20;} // 0 = 23
   if (xt>355 & xt<405 & yt>100 & yt<150){k=30;} // 1 = 33
   if (xt>405 & xt<455 & yt>100 & yt<150){k=40;} // 2 = 43
   if (xt>305 & xt<355 & yt>150 & yt<200){k=50;} // 3 = 53
   if (xt>355 & xt<405 & yt>150 & yt<200){k=60;} // 4 = 63
   if (xt>405 & xt<455 & yt>150 & yt<200){k=70;} // 5 = 73
   if (xt>305 & xt<355 & yt>200 & yt<250){k=80;} // 6 = 83
   if (xt>355 & xt<405 & yt>200 & yt<250){k=90;} // 7 = 93
   if (xt>405 & xt<455 & yt>200 & yt<250){k=100;}// E = 103
   mode = mode + k;                              //
  }                                              //
  // LABEL ---------------------------------------------------------------
  if (xt>300 & xt<350 & yt>5 & yt<35){           // LABEL MENU AREA
    mode = 3;                                    //
    int n = 0;                                   //
    myGLCD.setColor(255,0,0);                    // "LABEL"
    myGLCD.fillRect(301,6,349,34);               // "LABEL"
    myGLCD.setFont(SmallFont);                   //
    myGLCD.setFont(SmallFont);                   // Small Font
    myGLCD.setColor(255,255,255);                // "LABEL"
    myGLCD.setBackColor(255,0,0);                // "LABEL"
    myGLCD.print("LABEL",307,15);                // "LABEL"
    //-------------------------------------------//
    myGLCD.setColor(255,255,255);                // Oscillo back clear
    myGLCD.fillRect(300,45,470,314);             // Oscillo back clear
    myGLCD.setColor(0,0,0);                      // waku
    myGLCD.drawRect(300,95,460,255);             // waku
    myGLCD.setColor(255,255,255);                // waku
    myGLCD.fillRect(301,96,459,254);             // waku
    //-------------------------------------------//
    int x1=305,y1=100,wd=50,xd=50;               // key pad
    for (int y=0; y<3; y++){                     // key pad
     for (int x=0; x<3; x++ ){                   // key pad
      myGLCD.setColor(255,255,0);                // waku
      myGLCD.drawRect(x1+x*xd,y1+y*xd,x1+x*xd+wd,y1+wd+y*xd);
      myGLCD.setColor(100,100,100);              // fill
      myGLCD.fillRect(x1+x*xd+1,y1+1+y*xd,x1+x*xd+wd-1,y1+wd-1+y*xd);
      if ( n<8 ){                                // key = 0 to 7
        myGLCD.setFont(BigFont);                 // Bigfont
        myGLCD.setColor(255,255,255);            //
        myGLCD.setBackColor(100,100,100);        //
        myGLCD.print(String(n),323+x*xd,y1+18+y*xd); // key no
      }                                          //
      if ( n == 8 ){                             // key = ENT
        myGLCD.setFont(BigFont);                 //
        myGLCD.setColor(255,255,255);            //
        myGLCD.setBackColor(100,100,100);        //
        myGLCD.print("ENT",306+x*xd,y1+18+y*xd); //
      }                                          //
      n++;                                       // key no +
     }                                           //
    }                                            //
  }                                              //
  //---------------------------------------------//
  if ( mode == 4 ){                              // BIT
   int k;                                        //
   //     x1       x2       y1       y2          // BIT KEY AREA
   if (xt>305 & xt<355 & yt>100 & yt<150){k=120;}// 0 = 123
   if (xt>355 & xt<405 & yt>100 & yt<150){k=130;}// 1 = 133
   if (xt>405 & xt<455 & yt>100 & yt<150){k=140;}// 2 = 143
   if (xt>305 & xt<355 & yt>150 & yt<200){k=150;}// 3 = 153
   if (xt>355 & xt<405 & yt>150 & yt<200){k=160;}// 4 = 163
   if (xt>405 & xt<455 & yt>150 & yt<200){k=170;}// 5 = 173
   if (xt>305 & xt<355 & yt>200 & yt<250){k=180;}// 6 = 183
   if (xt>355 & xt<405 & yt>200 & yt<250){k=190;}// 7 = 193
   if (xt>405 & xt<455 & yt>200 & yt<250){k=200;}// 8 = 203
   if (xt>305 & xt<355 & yt>250 & yt<300){k=210;}// 9 = 213
   if (xt>355 & xt<405 & yt>250 & yt<300){k=220;}// E = 223
   if (xt>405 & xt<455 & yt>250 & yt<300){k=230;}// E = 233
   mode = mode + k;                              //
  }                                              //
  // BIT ---------------------------------------------------------------
  if ( xt>360 & xt<410 & yt>5 & yt<35){          // BIT MENU AREA
   if ( mode == 0 ){                             // rx mode
     mode = 4;                                   // MODE 4
     int n = 0;                                  // KEY NO
     //------------------------------------------//
     myGLCD.setColor(0,0,0);                     // waku
     myGLCD.drawRect(300,95,460,255);            // waku
     myGLCD.setColor(255,255,255);               // waku
     myGLCD.fillRect(301,96,459,254);            // waku
     //------------------------------------------//
     myGLCD.setColor(255,0,0);                   //
     myGLCD.fillRect(361,6,409,34);              //
     myGLCD.setFont(SmallFont);                  // Small Font
     myGLCD.setColor(255,255,255);               // "BIT"
     myGLCD.setBackColor(255,0,0);               // "BIT"
     myGLCD.print("BIT",375,15);                 // "BIT"
     //------------------------------------------//
     myGLCD.setColor(255,255,255);               // Oscillo back clear
     myGLCD.fillRect(300,50,470,314);            // Oscillo back clear
     myGLCD.setColor(0,0,0);                     // waku
     myGLCD.drawRect(300,95,460,305);            // waku
     myGLCD.setColor(255,255,255);               // waku
     myGLCD.fillRect(301,96,459,304);            // waku
     //------------------------------------------//
     int x1=305,y1=100,wd=50,xd=50;              // key pad
     for (int y=0; y<4; y++){                    // key pad
      for (int x=0; x<3; x++ ){                  // key pad
        myGLCD.setColor(255,255,0);              // waku
        myGLCD.drawRect(x1+x*xd,y1+y*xd,x1+x*xd+wd,y1+wd+y*xd);
        myGLCD.setColor(100,100,100);            // fill
        myGLCD.fillRect(x1+x*xd+1,y1+1+y*xd,x1+x*xd+wd-1,y1+wd-1+y*xd);
        if ( n<10 ){                             // key = 0 to 7
          myGLCD.setFont(BigFont);               // Bigfont
          myGLCD.setColor(255,255,255);          //
          myGLCD.setBackColor(100,100,100);      //
          myGLCD.print(String(n),323+x*xd,y1+18+y*xd); // key no
        }                                        //
        if ( n == 11){                           // key = ENT
          myGLCD.setFont(BigFont);               //
          myGLCD.setColor(255,255,255);          //
          myGLCD.setBackColor(100,100,100);      //
          myGLCD.print("ENT",306+x*xd,y1+18+y*xd);
        }                                        //
        n++;                                     // key no +
       }                                         //
      }                                          //
    }                                            //
    else{mode = 0;delay(50);}                    //
   }                                             //
   //--------------------------------------------//------------------------
   if ( mode == 6 ){                             // MONITOR
   int k;                                        //
   //     x1       x2       y1       y2          // MONITOR MODE AREA
   if (xt>305 & xt<355 & yt>100 & yt<150){k=320;}// 0 = 323
   if (xt>355 & xt<405 & yt>100 & yt<150){k=330;}// 1 = 333
   if (xt>405 & xt<455 & yt>100 & yt<150){k=340;}// E = 343
   mode = mode + k;                              //
  }                                              //
  // MONITOR --------------------------------------------------------------
  if ( xt>420 & xt<470 & yt>5 & yt<35){          // MONITOR MEMU AREA
   if ( mode == 0 ){                             // rx mode
     mode = 6;                                   // MODE 6
     //------------------------------------------// 420,5,470,35
     myGLCD.setColor(255,0,0);                   //
     myGLCD.fillRect(421,6,469,34);              //
     myGLCD.setFont(SmallFont);                  // Small Font
     myGLCD.setColor(255,255,255);               // "BIT"
     myGLCD.setBackColor(255,0,0);               // "BIT"
     myGLCD.print("MON",435,15);                 // "BIT"
     //------------------------------------------//
     myGLCD.setColor(0,0,0);                     // waku
     myGLCD.drawRect(300,95,460,155);            // waku
     myGLCD.setColor(255,255,255);               // Oscillo back clear
     myGLCD.fillRect(300,45,470,314);            // Oscillo back clear
     //------------------------------------------//
     myGLCD.setColor(255,255,0);                 // waku
     myGLCD.drawRect(305,100,355,150);           //
     myGLCD.setColor(100,100,100);               // fill
     myGLCD.fillRect(306,101,354,149);           //
     myGLCD.setFont(BigFont);                    // Bigfont
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print("0",323,118);                  // key no
     //------------------------------------------//     
     myGLCD.setColor(255,255,0);                 // waku
     myGLCD.drawRect(355,100,405,150);           //
     myGLCD.setColor(100,100,100);               // fill
     myGLCD.fillRect(356,101,404,149);           //
     myGLCD.setFont(BigFont);                    // Bigfont
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print("1",373,118);                  // key no
     //------------------------------------------//     
     myGLCD.setColor(255,255,0);                 // waku
     myGLCD.drawRect(405,100,455,150);           //
     myGLCD.setColor(100,100,100);               // fill
     myGLCD.fillRect(406,101,454,149);           //
     myGLCD.setFont(BigFont);                    // Bigfont
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print("ENT",406,118);                // key no
    }                                            //
    else{mode = 0;delay(50);}                    // mode 0
   }                                             //
  // MONITOR ------------------------------------//------------------------
  return mode;                                   //
}                                                //
//=========================================================================
int key(int mode){                               // LABEL KEY INPUT
  if ( mode == 103 ){                            // mode 3 enter action
       myGLCD.setFont(BigFont);                  //
       myGLCD.setColor(255,255,255);             //  
       myGLCD.setBackColor(100,100,100);         //  
       myGLCD.print(LBL,306,70);                 //
       myGLCD.setColor(bk,bk,bk);                //
       myGLCD.fillRect(301,6,349,34);            //
       myGLCD.setFont(SmallFont);                // Small Font
       myGLCD.setColor(0,0,0);                   //
       myGLCD.setBackColor(bk,bk,bk);            //
       myGLCD.print(LBL,315,15);                 // LABEL disp write
       mode = 0;                                 // rx mode
     }                                           //
     else{                                       //
     LBL = LBL + String(int(mode/10)-2);         // key read add
     int L = LBL.length();                       //
     if (L==0 | L==1 | L==2 | L==3){ goto p1;}   // 0,1,2,3
     if (L>3){LBL = LBL.substring(L-3,L+1);}     //
     p1:                                         //
     myGLCD.setFont(BigFont);                    //
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print(LBL,306,70);                   //
     mode = 3;                                   // key input mode
     }                                           //
   return mode;                                  //  
}                                                //
//=========================================================================
int bkey(int mode){                              // BIT KYE INPUT
  if ( mode == 234 ){                            // mode 4 enter action
       myGLCD.setFont(BigFont);                  //
       myGLCD.setColor(255,255,255);             //  
       myGLCD.setBackColor(100,100,100);         //  
       myGLCD.print(BIT,306,70);                 //
       myGLCD.setColor(bk,bk,bk);                //
       myGLCD.fillRect(361,6,409,34);            //
       myGLCD.setFont(SmallFont);                // Small Font
       myGLCD.setColor(0,0,0);                   //
       myGLCD.setBackColor(bk,bk,bk);            //
       myGLCD.print(BIT,380,15);                 // bit disp write
       mode = 0;                                 // rx mode
     }                                           //
     else{                                       //
     BIT = BIT + String(int(mode/10)-12);        // key read add
     int L = BIT.length();                       //
     if (L==0 | L==1 | L==2){ goto p1;}          // 0,1,2
     if (L>2){BIT = BIT.substring(L-2,L+1);}     //
     p1:                                         //
     myGLCD.setFont(BigFont);                    //
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print(BIT,306,70);                   //
     mode = 4;                                   // key input mode
     }                                           //
   return mode;                                  //  
}                                                //
//=========================================================================
int mkey(int mode){                              // MONITOR KYE INPUT
  if ( mode == 346 ){                            // mode 6 enter action
       myGLCD.setFont(BigFont);                  // Oscillo disp
       myGLCD.setColor(255,255,255);             //  
       myGLCD.setBackColor(100,100,100);         //  
       myGLCD.print(MON,306,70);                 // oscillo bit disp
       myGLCD.setColor(bk,bk,bk);                //
       myGLCD.fillRect(421,6,469,34);            //
       myGLCD.setFont(SmallFont);                // Small Font
       myGLCD.setColor(0,0,0);                   //
       myGLCD.setBackColor(bk,bk,bk);            //
       myGLCD.print(MON,443,15);                 // bit button disp write
       mode = 0;                                 // rx mode
     }                                           //
     else{                                       //
     MON = MON + String(int(mode/10)-32);        // key read add
     int L = MON.length();                       //
     if (L==0 | L==1){ goto p1;}                 // 0,1
     if (L>1){MON = MON.substring(L-1,L+1);}     //
     p1:                                         //
     myGLCD.setFont(BigFont);                    //
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print(MON,306,70);                   //
     mode = 6;                                   // key input mode
     }                                           //
   return mode;                                  //  
}                                                //

Written by macsbug

9月 28, 2014 @ 11:42 am

カテゴリー: Arduino

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト / 変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト / 変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト / 変更 )

Google+ フォト

Google+ アカウントを使ってコメントしています。 ログアウト / 変更 )

%s と連携中

%d人のブロガーが「いいね」をつけました。