スマホもどきを作る @ トラ技Jr

トラ技Jr.1月号にてaitendoで売っているやすいLCDの記事を担当することになりました。

二度目の寄稿となります。

 

記事の中で、LCDを使用した製作の作品例として”スマホもどき”を紹介しました。

今回は、スマホもどきの簡単な説明とCADデータ等を載せます。

その前に記事で書ききれなかった、LCDの細かい制御について書こうと思います。

 

 

■LCDを使う

電子工作をやっている方は、きっと表示器としては以下の遷移をたどっていく方が多いと思います。

LED → マトリクスLED → キャラクタディスプレイ(文字/記号のみ) → フルカラーLCD

LEDは電流流せば光るし、マトリクスは、制御線たくさんあれば簡単に制御できます。

キャラクタディスプレイは、制御方法がそれほど難しくないので、紙ぺら3枚くらいのデータシートを読めば、ライブラリを一から作れます。

一方、キャラクタディスプレイとフルカラーLCDの間には大きな壁があって、突然データシートの量が多くなるのと、使用するコマンドの数が増えます。

なので、結局誰かさんが作ったライブラリを使用するだけで、細かい制御方法は理解できないままという結果になると勿体無い気がするので、軽くですが記事の中で細かいところの制御について触れました。

今回は制御方法についてもう少し細かく説明します。最後のほうにサンプルコードもあるのでご参考まで。

別のページに画像を16bitカラーモードのデータに変換するアプリのソースコードも載せているので、そちらもご参考まで。

 

 

■ST7735

LCDのデータシート

まずはデータシートを見るのですが、重要なのは、77ページからのコマンドです。

このコマンドを使えばやりたい操作ができます。

それぞれのコマンドが効果を得るためには適切なフローをたどらなければならない場合があります。

コマンドの使い方は詳細が載っているので、使いたいコマンドが決まったら確認する。

 

①バックライトを点灯する

とりあえず、LCDのバックライトをつけてみます。

多分、一面真っ白な画面が出てくるはずです。

何も制御していない状態だと、真っ白な画面がつく、という事実を確認しました。

 

②ドライバの初期状態を確認する

128*160のLCDの場合、ドライバは初期状態に以下の表の状態になります。

 

 

簡単に説明すると、以下の状態です。

・スリープモードに入っている

・ディスプレイはOFFの状態

・スタートColumnアドレス:0000h エンドColumnアドレス:007Fh

・スタートRowアドレス:0000h  エンドRowアドレス:009Fh

・カラーモード:8bit

 

③初期状態から操作できる状態に設定を変更

この初期状態を使える状態にします。

打つコマンドは以下です。

0x01      : ソフトウェアリセット

0x11      : スリープからの復帰

0x36(引数あり) : メモリアクセス制御

0x3A(引数あり) : カラーモードの変更

0x29(引数あり) : ディスプレイON

0x2A(引数あり) : Columnアドレスの変更

0x2B(引数あり) : Rowアドレスの変更

引数を取るコマンドがあります。引数を複数とるコマンドもあります。

この場合、コマンドを打った後に適切な数値を送信します。

 

④送信データを用意する

いよいよ表示を行います。

グラデーション表示だと数式で処理できるのでデータを用意する必要がなく楽です。

以下数例のグラデーションプログラムを載せます。

全体のプログラムは下にまとめて載せます。

 

ただただ、x方向やy方向に進むたびに塗る色を変えていくだけです。

 

 


//example 1
for(y=160; y>0; y--) {
 for(x=128; x>0; x--) {
  spiwrites(0xF8);
  spiwrites(0x1F);
 }
}


//example 2
for(y=160; y>0; y--) {

 if((i&0x8F1F)<0x8F1F){
  if(rb>=5){
    i += 0x0801;
    rb = 0;
  }
 rb++;
}
if((i&0x7E0)<0x7E0){
 if(gr==3){
  i+=0x20;
 }
 if(gr==5){
  i+=0x20;
  gr=0;
 }
 gr++;
}
 for(x=128; x>0; x--) {
  spiwrites(i>>8);
  spiwrites(i);
 }
}


//example 3
for(y=160; y>0; y--) {
 if(rb>=5){
  i -= 0x0800;
  i += 0x0001;
  rb = 0;
 }
 i = i|0x07E0;
 for(x=128; x>0; x--) {
  if(gr==2){
   i-=0x20;
  }if(gr==4){
   i-=0x20;
  }if(gr==7){
   i-=0x20;
   gr=0;
  }

  spiwrites(i>>8);
  spiwrites(i);
  gr++;
 }
 rb++;
}

 

⑤画像データを表示する

設定した色モードに対応させた画像のバイナリデータを用意しなければなりません。

ネットで簡単にできるソフトがないか探しましたがなかったので、作りました。別ページにあります。

短いので中身は読んで使ってください。気が向いたら説明を入れるようにします。

できたバイナリデータは以下のような感じになります。

長いのでピピっと飛ばしてください。

 


const uint16_t PROGMEM Rcmd2s[40][32] = {
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834}
};

 

 

⑥完成したサンプルコード

全体のコードは以下になります。

貼り付けるとインデント無くなるので、見にくいですが、このままで。申し訳ない。

 


#include <SPI.h>
#include "disp.h"
#include <avr/sleep.h>

#define TFT_CS 2
#define TFT_RST 4
#define TFT_DC 3
#define TFT_SCLK 13
#define TFT_MOSI 11

volatile uint8_t *csport,*rsport,*clkport,*dataport;
uint32_t cspinmask,rspinmask,datapinmask,clkpinmask;

int y,x;
#define DELAY 0x80
void commandLists(const uint8_t *addr);
void writecommands(uint8_t c);
void writedatas(uint8_t c);
void spiwrites(uint8_t c);

const uint16_t PROGMEM Rcmd2s[40][32] = {
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x055D,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8,0x07F8},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0x07D8,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0x03FC,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834},
{0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834,0xE834}
};
static const uint8_t PROGMEM Rcmd1s[] = { // Init for 7735R, part 1 (red or green tab)
5, // 15 commands in list:
ST7735_SWRESET, DELAY, // 1: Software reset, 0 args, w/delay
150, // 150 ms delay
ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, 0 args, w/delay
255, // 500 ms delay
ST7735_MADCTL , 1 , // 14: Memory access control (directions), 1 arg:
0x03, // row addr/col addr, bottom to top refresh
ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay:
0x05, // 4 commands in list:
ST7735_DISPON , DELAY, // 4: Main screen turn on, no args w/delay
100 }; // 100 ms delay

void setup(void) {
 Serial.begin(9600);
 Serial.println("Hello World! Display Test!");

 pinMode(TFT_CS , OUTPUT);
 pinMode(TFT_DC, OUTPUT);
 pinMode(TFT_RST, OUTPUT);

 csport = portOutputRegister(digitalPinToPort(TFT_CS));
 rsport = portOutputRegister(digitalPinToPort(TFT_DC));

 cspinmask = digitalPinToBitMask(TFT_CS);
 rspinmask = digitalPinToBitMask(TFT_DC);

 SPI.begin();
 SPI.setClockDivider(SPI_CLOCK_DIV4);
 SPI.setDataMode(SPI_MODE0);

 *csport &= ~cspinmask;
 pinMode(TFT_RST, OUTPUT);
 digitalWrite(TFT_RST, HIGH);
 delay(50);
 digitalWrite(TFT_RST, LOW);
 delay(50);
 digitalWrite(TFT_RST, HIGH);
 delay(50);

 commandLists(Rcmd1s);

 writecommands(ST7735_CASET); // Column addr set
 writedatas(0x00);
 writedatas(0x02); // XSTART
 writedatas(0x00);
 writedatas(129); // XEND

 writecommands(ST7735_RASET); // Row addr set
 writedatas(0x00);
 writedatas(0x01); // YSTART
 writedatas(0x00);
 writedatas(160); // YEND

 writecommands(ST7735_RAMWR); // write to RAM

 uint8_t r = 0x00, g = 0x00, b=0x00;

 *rsport |= rspinmask;
 *csport &= ~cspinmask;
 for(y=160; y>0; y--) {
  for(x=128; x>0; x--) {
   spiwrites(r);
   spiwrites(g);

  r += 0x01;
 }
 g += 0x01;
}

 *csport |= cspinmask;

 delay(2000);
 writecommands(ST7735_RAMWR); // write to RAM

 *rsport |= rspinmask;
 *csport &= ~cspinmask;
 for(y=160; y>0; y--) {
  for(x=128; x>0; x--) {
   spiwrites(0xF8);
   spiwrites(0x1F);
  }
 }

 *csport |= cspinmask;

 delay(2000);

 uint16_t i=0;
 int rb = 0;
 int gr = 0;

 writecommands(ST7735_RAMWR); // write to RAM

 *rsport |= rspinmask;
 *csport &= ~cspinmask;
 for(y=160; y>0; y--) {

 if((i&0x8F1F)<0x8F1F){
  if(rb>=5){
   i += 0x0801;
   rb = 0;
  }
 rb++;
 }
 if((i&0x7E0)<0x7E0){
  if(gr==3){
   i+=0x20;
  }
  if(gr==5){
   i+=0x20;
   gr=0;
  }
  gr++;
 }
 for(x=128; x>0; x--) {
  spiwrites(i>>8);
  spiwrites(i);
 }
}

 *csport |= cspinmask;

 delay(1000);

 i=0xFFE0;
 rb = 0;
 gr = 0;
 writecommands(ST7735_RAMWR); // write to RAM

 *rsport |= rspinmask;
 *csport &= ~cspinmask;
 for(y=160; y>0; y--) {
  if(rb>=5){
   i -= 0x0800;
   i += 0x0001;
   rb = 0;
 }
 i = i|0x07E0;
 for(x=128; x>0; x--) {
  if(gr==2){
   i-=0x20;
  }if(gr==4){
   i-=0x20;
  }if(gr==7){
   i-=0x20;
   gr=0;
  }

  spiwrites(i>>8);
  spiwrites(i);
  gr++;
  }
  rb++;
 }
 *csport |= cspinmask;

 delay(2000);

 int vv =1,cc = 1;
 int v=0,c=0;
 writecommands(ST7735_RAMWR); // write to RAM

 *rsport |= rspinmask;
 *csport &= ~cspinmask;
 for(y=160; y>0; y--) {
  if(vv == 4){
   v++;
   vv = 0;
  }
  for(x=128; x>0; x--) {
   if(cc == 4){
    c++;
    cc=0;
   }
   spiwrites(Rcmd2s[v]>>8);
   spiwrites(Rcmd2s[v]);
   Serial.println(Rcmd2s[v],HEX);

   cc++;
  }
  cc=0;
  c=0;
  vv++;
 }

 *csport |= cspinmask;

 delay(2000);
}

void loop(){
 Serial.println("SLEEP");
 delay(500);
 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
 sleep_mode();
}

void commandLists(const uint8_t *addr) {

 uint8_t numCommands, numArgs;
 uint16_t ms;

 numCommands = pgm_read_byte(addr++); // Number of commands to follow
 Serial.println(numCommands);
 while(numCommands--) { // For each command...
 writecommands(pgm_read_byte(addr++)); // Read, issue command
 numArgs = pgm_read_byte(addr++); // Number of args to follow
 ms = numArgs & DELAY; // If hibit set, delay follows args
 numArgs &= ~DELAY; // Mask out delay bit
 while(numArgs--) { // For each argument...
  writedatas(pgm_read_byte(addr++)); // Read, issue argument
 }

 if(ms) {
  ms = pgm_read_byte(addr++); // Read post-command delay time (ms)
   if(ms == 255) ms = 500; // If 255, delay for 500 ms
    delay(ms);
   }
  }
 }

 inline void spiwrites(uint8_t c) {
  SPI.transfer(c);
 }

 void writecommands(uint8_t c) {
  Serial.println("COMMAND");
  *rsport &= ~rspinmask; //RS = LOW;
  Serial.println(*rsport,BIN);
  *csport &= ~cspinmask; //CS = LOW;
  Serial.println(*csport,BIN);
  spiwrites(c);
  *csport |= cspinmask; //CS = HIGH;
  Serial.println(*csport,BIN);
 }
 void writedatas(uint8_t c) {
  Serial.println("DATA");
  *rsport |= rspinmask;
  Serial.println(*rsport,BIN);
  *csport &= ~cspinmask;
  Serial.println(*csport,BIN);
  spiwrites(c);
  *csport |= cspinmask;
  Serial.println(*csport,BIN);
 }

 

大切なのは、コマンド、コマンドの引数、コマンドを打つ時の制約(適切なフローを取ること)

これを守れば、簡単にLCDの操作ができる。

ドライバの中のRAMはSRAMなので、コマンド何も打っていない状態や、LCDの操作を何もしない状態だとLCDは最後の制御信号のまま表示が続きます。

SRAMなので当たり前ですが、この仕組みを使えば回路に色々な工夫を入れ込むことができるようになります。SRAMは貴重なので、有効活用すること。

 

 

■”スマホもどき”の紹介

スマホもどきは、スマホのようなUIを持ったSMS送受信機です。

主な仕様は、SMSを送信することと、受信することです。それだけですが、LCDを使用することで、スマホのようなUIにできて愛着が増します。

以下に、プログラムとCADファイルを載せます。

3GIMが高いのでなかなか真似できないかもしれませんが。。。製作の参考になればと思います。

 

##KiCAD

LCD_SMS

 

 

##Arduinoプログラム


#include <SoftwareSerial.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h>
#include <MsTimer2.h>
#include "Adafruit_ST7735.h" // Hardware-specific library
#define TFT_CS 7
#define TFT_RST 5
#define TFT_DC 6
#define TFT_SCLK 13
#define TFT_MOSI 11

// Option 1 (recommended): must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#define BT_DEC 12
#define BT_NEXT 10
#define BT_RETURN 9
#define ST7735_PGREEN 0x97F9
#define ST7735_PPINK 0xFE7D

String rt = "";
String errorMsg = "412";
boolean stateFlag = 0;

struct phone {
 int num;
 char* names;
 char* phoneNum;
};

char* message[] = {
 "Hello World!",
 "Good morning!",
 "Good night!",
 "OK!(*^_^)b",
 "Sure!(*^o^*)",
 "No problem!",
 "This is LongLongLong message!"
};

struct phone member[] = {
 {0, "Eri Yamamoto", "08017098346"},
 {1, "Hiroyuki Ikegami", "08040350786"}
};

void setup(void) {
 Serial.begin(9600);
 //Serial.print("Hello! ST7735 TFT Test");

 pinMode(BT_DEC, INPUT);
 pinMode(BT_NEXT,INPUT);
 pinMode(BT_RETURN,INPUT);

 // Use this initializer if you're using a 1.8" TFT
 tft.initR(INITR_BLUETAB); // initialize a ST7735S chip, black tab

 tft.fillScreen(ST7735_BLACK);
 delay(1000);

 //while(!Serial.available());
 //iemSerial.print("$YL\n");
 //Serial.print("$YL\n");

 for(int i=0; i<2; i++){
  Serial.println("$YL 1");
  delay(1000);
  Serial.println("$YL 0");
  delay(1000);
 }
 delay(1000);
 Serial.println("$YV");
 delay(1000);
 while(!Serial.available());

 Serial.println("$YD TABrain \"$x49$x3D$xD8$xC9$xCE$x98$xDB$x3D$x22$xCA$x56$x84$xCA$xA2$x97$x7F$xBB$xC5$x6D$xEC$xBE$xAF$x39$x89$x47$xA7$xFF$x67$x79$x81$xA3$xBD$x66$x9D$xBD$xDD$x5B$x5F$x58$x89$x46$x5D$x57$xEB$x95$x23$x29$xE3$x78$x23$x32$x31$x49$xB2$xD0$xE9$x47$xC0$x16$x34$xB5\"");
 delay(1500);
 while(!Serial.available());

 Serial.println("$PS 12");
 delay(1500);
 while(!Serial.available());
 tft.fillScreen(ST7735_PGREEN);
 tft.fillRect(0,140,128,20,ST7735_BLACK);
 tft.fillRect(0,120,128,20,ST7735_PPINK);
 tft.setTextSize(1);
 delay(1000);

 //MsTimer2::set(5000,receiveSMS);
 //MsTimer2::start();
}
 char i = 0,j = 0;
 char x = 0,y = 0;

void loop() {
 //Push Decide button
 if(digitalRead(BT_DEC) == LOW){
  delay(200);
  if(stateFlag == 0){
   stateFlag++;
  }else{
   sms(member[j-1].phoneNum, message[i-1]);
  x=0;
   Serial.println("This is DEC!");
   if(strlen(message[i]) <= 15){
    tft.fillRoundRect(25 - x, 10 + y, 95, 15, 4, ST7735_WHITE);
    tft.setTextColor(ST7735_BLACK);
    tft.setCursor(30 - x, 12 + y);
    tft.setTextWrap(true);
    tft.print(message[i-1]);
   }else{
    int len = strlen(message[i])/15;
    Serial.println(len);
    tft.fillRoundRect(25 - x, 10 + y, 95, 15 * len, 4, ST7735_WHITE);
   }
   y += 20;
  }
  delay(100);
 }

 //Push Next button
 if(digitalRead(BT_NEXT) == LOW){
  delay(200);
  Serial.println("This is NEXT!");
  if(stateFlag == 1){
   tft.setTextColor(ST7735_WHITE);
   tft.fillRect(0,140,128,20,ST7735_BLACK);
   tft.setCursor(10, 146);
   tft.setTextWrap(true);
   tft.print(message[i]);
   i++;
   if(i>=7){
    i = 0;
   }
  }else{
   tft.setTextColor(ST7735_BLACK);
   tft.fillRect(0,120,128,20,ST7735_PPINK);
   tft.setCursor(10, 126);
   tft.setTextWrap(true);
   tft.print(member[j].names);
   j++;
   if(j>=2){
    j = 0;
   }
  }
  delay(100);
 }

 //Push Return button
 if(digitalRead(BT_RETURN) == LOW){
  delay(200);
   if(stateFlag == 0);
   else{
    stateFlag = 0;
   }
  delay(200);
  }
 }

 void sms(char *num, char *sm){
  char str[30];
  char str1[] = "$SS ";
  char str2[] = " \"";
  char str3[] = "\" ASCII\n";
  sprintf(str,"%s%s%s%s%s\n",str1,num,str2,sm,str3);
  Serial.print(str);
  Serial.flush();
 }

 void receiveSMS(){
 String rec = "";
 char *command, *pNum, *msg;
 char all[30]; 

 Serial.println("$SR");
 Serial.flush();

 if(Serial.available()){
  rec = Serial.readStringUntil('\n');
  rec.toCharArray(all,30);
  command = strtok(all," ");
  pNum = strtok(NULL, " ");
  msg = strtok(NULL, " ");
 }

 if(rec.startsWith("$SR=OK")){
  x = 18;
  tft.fillRoundRect(25 - x, 10 + y, 95, 15, 4, ST7735_WHITE);
  tft.setTextColor(ST7735_BLACK);
  tft.setCursor(30 - x, 12 + y);
  tft.setTextWrap(true);
  tft.print(msg);
  y += 20;
 }
}

One Comment

  1. Hello do you know that you can increase your conversion ratio couple of times and earn extra cash every day.
    There is incredible landing pages tool. It’s very
    easy even for noobs, if you are interested simply search
    in gooogle: pandatsor’s tools

コメントを残す

メールアドレスが公開されることはありません。