MTM05でArduinoを買ったのでちょっと触ってみた。
まずは昔買って一度も使っていなかったLEDマトリクスを光らせてみることに。
いきなり困ったことにLEDマトリクスのピン配置が全くわからん
データシートにピン配置書いてないし・・・
http://strawberry-linux.com/pub/YSM-1288CR3G2C.pdf
と思ってググったらsparkfunのコメント欄に答えがあった
http://www.sparkfun.com/commerce/product_info.php?products_id=681
On mine, pin one was present on the left-most pin when looking at the side with “YS” stamp (see picture):
http://retfie.com/front.jpgI also took a picture of the underside to locate pin one based upon the PCB.
When looking at the PCB text (underneath the epoxy coating), pin one is located bottom left (see picture):
http://retfie.com/bottom.jpg
ということで、YS”スタンプが手前に来るように上から見て、左下が1pin、右下が12pin、右上が13pin、左上が24pinらしい。
そしてこのLED微妙に2.54ピッチじゃないんだな、めんどくさ。ミニブレッドボードが意外なところで活躍した。
さて光らせようと思ったが、8×8のLEDを2色ですべて光らせるには24本のIOが必要だったので、ArduinoのIOでは全然足りない。Decoderでもあればいいけど、そんなものは手元にないので(なぜか表面実装の74238があったけど半田付けしたくないのでパス)、すべて光らせるのはあきらめて、4×8で一色だけで光らせることにした。
これだと、columnに8本、rowに4本の12本でいけそう。LEDドライバもめんどくさいので今回は無しで。
書いたコードはこんな感じ。
てっきりArduinoってJavaで書くのかと思ってたらCだったのね。Javaと思ってた理由はGUIの見た目がProcessingぽかったというだけだけど。
int cols[] = {2,3,4,5,6,7,8,9}; int rows[] = {10,11,12,13}; //int pinCount = 4; const int rowCount = 4; const int colCount = 8; int data[rowCount][colCount] = { {0,1,0,0, 0,1,0,0}, {1,1,1,0, 1,1,1,0}, {0,1,0,0, 1,0,0,0}, {0,1,1,0, 0,1,1,0} }; int shift = 0; // The setup() method runs once, when the sketch starts void setup() { // initialize the digital pin as an output: for(int i = 0; i < rowCount;++i){ pinMode(rows[i], OUTPUT); digitalWrite(rows[i], HIGH); } for(int i = 0; i < colCount;++i){ pinMode(cols[i], OUTPUT); } } void writedata(int shift) { for(int r = 0; r < rowCount;++r){ digitalWrite(rows[r], LOW); for(int c1 = 0; c1 < colCount;++c1){ int c = c1+shift; if( c >= colCount )c-=colCount; else if(c < 0 )c += colCount; if( data[r]1 == 1 ){ digitalWrite(cols[c1], HIGH); }else{ digitalWrite(cols[c1], LOW); } } delay(1); digitalWrite(rows[r], HIGH); } } // the loop() method runs over and over again, // as long as the Arduino has power void loop() { int delay = 60; for(int i = 0; i < delay ;i++){ writedata(shift); } shift++; shift =shift % colCount; }
基本はサンプルにあったblinkをいじってます。
謎の文字がスクロールします。
疲れたので今日はこれくらいにしよ。