EeePC901にLubuntu14.10入れてみる

電子工作から離れてしまいますが、使っていないEeePC901が出てきたのでLubuntu入れみてみます。XPサポート切れてますしね。

1.ISOイメージのダウンロード

こちら↓から、"PC 32bit Standard image disc"を選んでISOイメージをダウンロードします。

Lubuntu/GetLubuntu - Community Help Wiki https://help.ubuntu.com/community/Lubuntu/GetLubuntu


2.インストール用USBメモリの作成

こちら↓からUNetbootinをダウンロードします。

UNetbootin - Homepage and Downloads http://unetbootin.sourceforge.net/#other

USBメモリをPCに挿したらUNetbootinを実行して、下の"ディスクイメージ"を選び、1でダウンロードしたISOイメージを指定します。さらに下の方でタイプに"USBドライブ"を選択し、ドライブにはUSBメモリのドライブレターを指定します。

すべて設定できたら、OKをクリックするとUSBメモリにイメージが作成されます。


3.EeePCUSBメモリからBOOTするよう設定

EeePCUSBメモリを指して電源ONし、F2を連打してBOOTメニューに入ります。

右キーでBOOTのタブを選び、ドライブの起動順とHDDデバイスの起動順の両方をUSBメモリが1stに来るように設定します。設定後はF10でセーブ&再起動します。


4.Lubuntuのインストール

再起動後はインストーラが起動するので指示に従ってすすめてください。細かい設定はお好みでどうぞ。

この時点でうちのマシンだとタッチパッドが使えなくなり、USBマウスが必要になりました。(インストール完了後は復活)

インストールが終わったら再起動する前にUSBメモリを抜いて、再起動後はまたF2連打でBOOTメニューに入り、ドライブの起動順とHDDデバイスの起動順の両方をLubuntuをインストールしたSSDに戻します。

F10でセーブ&再起動すればLubuntuが起動するはずです。


5.radikoのインストール

LinuxマシンになったEeePCですが、radikoでラジオを聞けるようにして家人にあげました。

radikoはブラウザからでもアクセスできますが、ラジオ専用機なので使い勝手を考えてガジェットを入れておきました。

ガジェット用にまずAdobe Airを入れます。こちら↓参照で。

萌え萌えmoebuntu Ubuntu 12.10でAdobe AIR http://moebuntu.blog48.fc2.com/blog-entry-442.html

ガジェットはこちら↓からダウンロードできますので、ご参考まで…。

radiko.jp http://radiko.jp/?page=download

2.4インチLCD for さくら

前回、表示が乱れて使えなかったと書いた2.4インチLCD for さくら、ですが、ツイッターでデモプログラムの作者様からご教示いただきまして、ソースを修正した結果、無事に表示が行えるようになりました。

ネットで拾ったテストプログラムをこのLCD用に変更して表示テストを行ってみたので、よかったらご覧ください。

元のソースは以下のURLのili9163.cとili9163.hです。

mspdev/lib430/src/liblcd

GR SAKURA + S93160

aitendoがGR SAKURAの販売を始めましたね。一緒に売りだされた液晶を買ってみたのですが、表示が乱れてしまいます。原因不明です。

悲しいので、以前aitendoで買ってあったS93160という型番の別の液晶をつないでみました。

こちらは動作しました。良かったです。

GR KURUMI + フルカラーLEDマトリクス(その2)

前回、フルカラーLEDマトリクスを使ってみたのですが、やはりちらつきが気になるので色々試してみました。

TLC5940がらみの処理を見直しまして、まあまあ納得いく出来にはなったかと思うのですが、いかがでしょう。

TLC5940はGSCLKというピンに4096回パルスを入れると、事前にシリアルI/Fで設定した0〜4095の数値に応じてPWM動作するのですが、ここに時間がかかっており、ダイナミック点灯時のちらつきの原因となっていました。

4096回=4096段階に輝度が調節できるというのがTLC5940のウリではあるのですが、背に腹は変えられず512回に減らしました。BLANKピンをHIGHにするとGSCLKの処理を中断できるので、512回パルス入れた後にその操作を行っています。

/*GR-KURUMI Sketch Template Version: V1.00*/
#include <RLduino78.h>

#define NUM_5940    2

#define GSCLK_PIN   3

#define COM0_PIN    4
#define COM1_PIN    5
#define COM2_PIN    6

#define VPRG_PIN    7
#define BLANK_PIN   8
#define XLAT_PIN    9

#define SIN_PIN     11
#define SCLK_PIN    13

#define COLOR_DEPTH 512
#define COLOR_MULTIPLIER (COLOR_DEPTH/256)

void set_dc( void );
void set_gs_setting( int index );
void proc_gsclk( int index );
void proc_update(unsigned long u32ms);
void disp_update( void );
void set_gsval( int index );
void set_row( int index );
void shift_color( void );

int gsupdate = 0;
int dispindex = 0;

byte dcval[NUM_5940][16] = {
    {0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30},
    {0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30},
};

word gsval[NUM_5940][16];

typedef unsigned long RGB;

#define GetRED(x) (byte)(((x)>>16)&0xff)
#define GetGREEN(x) (byte)(((x)>>8)&0xff)
#define GetBLUE(x) (byte)((x)&0xff)

#define SetRGB(r,g,b) (((r)<<16)|((g)<<8)|(b))
RGB dots[8][8] = {
    { 0x000001, 0x000002, 0x000008, 0x000010, 0x000020, 0x000040, 0x000080, 0x0000E0 },
    { 0x000100, 0x000200, 0x000800, 0x001000, 0x002000, 0x004000, 0x008000, 0x00E000 },
    { 0x010000, 0x020000, 0x080000, 0x100000, 0x200000, 0x400000, 0x800000, 0xE00000 },
    { 0x000001, 0x000002, 0x000008, 0x000010, 0x000020, 0x000040, 0x000080, 0x0000E0 },
    { 0x000100, 0x000200, 0x000800, 0x001000, 0x002000, 0x004000, 0x008000, 0x00E000 },
    { 0x010000, 0x020000, 0x080000, 0x100000, 0x200000, 0x400000, 0x800000, 0xE00000 },
    { 0x000001, 0x000002, 0x000008, 0x000010, 0x000020, 0x000040, 0x000080, 0x0000E0 },
    { 0x000100, 0x000200, 0x000800, 0x001000, 0x002000, 0x004000, 0x008000, 0x00E000 }
};    

typedef struct {
  byte red;
  byte green;
  byte blue;
} s_dir_colors;
s_dir_colors dir_colors;

int row_index = 0;
int current_temp = 0;

// the setup routine runs once when you press reset:
void setup() {
  int i, j;

  row_index = 0;
  gsupdate = 0;
  dispindex = 0;

  dir_colors.red = 1;
  dir_colors.green = 0;
  dir_colors.blue = 0;

  for( i = 0; i < NUM_5940; i ++ ){
    for( j = 0; j < 16; j ++ ){
      gsval[i][j] = 0;
    }
  }

  pinMode(COM0_PIN, OUTPUT);
  pinMode(COM1_PIN, OUTPUT);
  pinMode(COM2_PIN, OUTPUT);

  pinMode(VPRG_PIN, OUTPUT);
  pinMode(BLANK_PIN, OUTPUT);
  pinMode(XLAT_PIN, OUTPUT);        // SS(STCP)

  pinMode(SIN_PIN, OUTPUT);
  pinMode(SCLK_PIN, OUTPUT);

  pinMode(GSCLK_PIN, OUTPUT);

  digitalWrite(COM0_PIN, LOW);
  digitalWrite(COM1_PIN, LOW);
  digitalWrite(COM2_PIN, LOW);

  digitalWrite(VPRG_PIN, HIGH);
  digitalWrite(BLANK_PIN, HIGH);
  digitalWrite(XLAT_PIN, LOW);

  digitalWrite(GSCLK_PIN, LOW);

  // start work
  set_dc();

  // 1st
  set_row( 0 );
  set_gs_setting( 0 );

  attachCyclicHandler(1, proc_update, 200);
}

// the loop routine runs over and over again forever:
void loop() {
  // check update
  disp_update();        // update

  // set row
  set_row( row_index );

  // set grayscale data
  set_gs_setting( row_index );
  proc_gsclk( row_index );

  // increment row
  row_index ++;
  if( row_index >= 8 ){
    row_index = 0;
  }
}

void set_dc( void )
{
  int i = 0;
  int j = 0;
  byte k = 0;

  // Dot Correction
  noInterrupts();

  P0.BIT.bit0 = 1;  // VPRG
  P1.BIT.bit3 = 0;  // XLAT

  P7.BIT.bit0 = 0;  // SCLK

  for( i = 0; i < NUM_5940; i ++  ){
    for( j = 0; j < 16; j ++ ){
      for( k = 0x20; k != 0x00; k >>= 1 ){
        P7.BIT.bit2 = ( ( dcval[i][j] & k ) == 0 ) ? 0 : 1;  // SIN

        P7.BIT.bit0 = 1;  // SCLK
        P7.BIT.bit0 = 0;  // SCLK
      }
    }
  }

  P1.BIT.bit3 = 1;  // XLAT
  P1.BIT.bit3 = 0;  // XLAT

  interrupts();
}

void set_gs_setting( int index )
{
  int i = 0;
  int j = 0;
  int k = 0;

  // Gray Scale
  set_gsval( index );

  noInterrupts();

  P0.BIT.bit0 = 0;  // VPRG
  P0.BIT.bit1 = 1;  // BLANK

  P1.BIT.bit3 = 0;  // XLAT
  P7.BIT.bit0 = 0;  // SCLK

  for( i = 1; i >= 0; i -- ){
    for( j = 0; j < 16; j ++ ){
      for( k = 11; k >= 0 ; k -- ){
        if( ( gsval[i][j] & ( 0x1 << k ) ) == 0 ){
          P7.BIT.bit2 = 0;
        }
        else{
          P7.BIT.bit2 = 1;
        }
        
        P7.BIT.bit0 = 1;  // SCLK
        P7.BIT.bit0 = 0;  // SCLK
      }
    }
  }

  P1.BIT.bit3 = 1;  // XLAT
  P1.BIT.bit3 = 0;  // XLAT

  P7.BIT.bit0 = 1;  // SCLK
  P7.BIT.bit0 = 0;  // SCLK

  P0.BIT.bit1 = 0;  // BLANK

  interrupts();
}

void proc_gsclk( int index )
{
  int i = 0;
  int gscnt = 0;

  // Gray Scale
  noInterrupts();

  P0.BIT.bit0 = 0;  // VPRG

  P1.BIT.bit3 = 0;  // XLAT
  P0.BIT.bit1 = 0;  // BLANK
  P7.BIT.bit0 = 0;  // SCLK

  gscnt = COLOR_DEPTH;

  for( i=0; i < gscnt; i ++ ){

    P1.BIT.bit6 = 1;  // GSCLK
    NOP();
    P1.BIT.bit6 = 0;  // GSCLK
    NOP();
  }

  P0.BIT.bit1 = 1;  // BLANK
  P0.BIT.bit1 = 0;  // BLANK

  interrupts();
}


void set_row( int index)
{
  // set ROW
  noInterrupts();

  switch( index ){
    case 0:
      P3.BIT.bit1 = 0;  // COM0
      P1.BIT.bit5 = 0;  // COM1
      P1.BIT.bit0 = 0;  // COM2
      break;
      
    case 1:
      P3.BIT.bit1 = 1;  // COM0
      P1.BIT.bit5 = 0;  // COM1
      P1.BIT.bit0 = 0;  // COM2
      break;

    case 2:
      P3.BIT.bit1 = 0;  // COM0
      P1.BIT.bit5 = 1;  // COM1
      P1.BIT.bit0 = 0;  // COM2
      break;

    case 3:
      P3.BIT.bit1 = 1;  // COM0
      P1.BIT.bit5 = 1;  // COM1
      P1.BIT.bit0 = 0;  // COM2
      break;

    case 4:
      P3.BIT.bit1 = 0;  // COM0
      P1.BIT.bit5 = 0;  // COM1
      P1.BIT.bit0 = 1;  // COM2
      break;

    case 5:
      P3.BIT.bit1 = 1;  // COM0
      P1.BIT.bit5 = 0;  // COM1
      P1.BIT.bit0 = 1;  // COM2
      break;

    case 6:
      P3.BIT.bit1 = 0;  // COM0
      P1.BIT.bit5 = 1;  // COM1
      P1.BIT.bit0 = 1;  // COM2
      break;

    case 7:
      P3.BIT.bit1 = 1;  // COM0
      P1.BIT.bit5 = 1;  // COM1
      P1.BIT.bit0 = 1;  // COM2
      break;
  
    default:
      break;
  }
  interrupts();
}

void proc_update( unsigned long u32ms )
{
  gsupdate = 1;
}

void set_gsval( int index )
{
  /* set gsval */
  gsval[0][0] = GetRED(dots[index][5]) * COLOR_MULTIPLIER;
  gsval[0][1] = GetBLUE(dots[index][4]) * COLOR_MULTIPLIER;
  gsval[0][2] = GetGREEN(dots[index][4]) * COLOR_MULTIPLIER;
  gsval[0][3] = GetRED(dots[index][4]) * COLOR_MULTIPLIER;
  gsval[0][4] = GetBLUE(dots[index][3]) * COLOR_MULTIPLIER;
  gsval[0][5] = GetGREEN(dots[index][3]) * COLOR_MULTIPLIER;
  gsval[0][6] = GetRED(dots[index][3]) * COLOR_MULTIPLIER;
  gsval[0][7] = GetBLUE(dots[index][2]) * COLOR_MULTIPLIER;
  gsval[0][8] = GetGREEN(dots[index][2]) * COLOR_MULTIPLIER;
  gsval[0][9] = GetRED(dots[index][2]) * COLOR_MULTIPLIER;
  gsval[0][10] = GetBLUE(dots[index][1]) * COLOR_MULTIPLIER;
  gsval[0][11] = GetGREEN(dots[index][1]) * COLOR_MULTIPLIER;
  gsval[0][12] = GetRED(dots[index][1]) * COLOR_MULTIPLIER;
  gsval[0][13] = GetBLUE(dots[index][0]) * COLOR_MULTIPLIER;
  gsval[0][14] = GetGREEN(dots[index][0]) * COLOR_MULTIPLIER;
  gsval[0][15] = GetRED(dots[index][0]) * COLOR_MULTIPLIER;

  gsval[1][0] = 0;
  gsval[1][1] = 0;
  gsval[1][2] = 0;
  gsval[1][3] = 0;
  gsval[1][4] = 0;
  gsval[1][5] = 0;
  gsval[1][6] = 0;
  gsval[1][7] = 0;
  gsval[1][8] = GetBLUE(dots[index][7]) * COLOR_MULTIPLIER;
  gsval[1][9] = GetGREEN(dots[index][7]) * COLOR_MULTIPLIER;
  gsval[1][10] = GetRED(dots[index][7]) * COLOR_MULTIPLIER;
  gsval[1][11] = GetBLUE(dots[index][6]) * COLOR_MULTIPLIER;
  gsval[1][12] = GetGREEN(dots[index][6]) * COLOR_MULTIPLIER;
  gsval[1][13] = GetRED(dots[index][6]) * COLOR_MULTIPLIER;
  gsval[1][14] = GetBLUE(dots[index][5]) * COLOR_MULTIPLIER;
  gsval[1][15] = GetGREEN(dots[index][5]) * COLOR_MULTIPLIER;
}

void disp_update( void )
{
  if( gsupdate == 1 ){
    shift_color();
    gsupdate = 0;
  }
}  

void shift_color( void )
{
  int y, x;
  RGB store;

  for( y=0; y<8; y++ ){
    store = dots[y][7];
    dots[y][7] = dots[y][6];
    dots[y][6] = dots[y][5];
    dots[y][5] = dots[y][4];
    dots[y][4] = dots[y][3];
    dots[y][3] = dots[y][2];
    dots[y][2] = dots[y][1];
    dots[y][1] = dots[y][0];
    dots[y][0] = store;
  }
}    

ご覧の通り、もはやArduino互換とは言いがたいソースになってしまいました。予算が許すならFPGAとか使った方が良いかもしれませんね。泣

GR KURUMI + フルカラーLEDマトリクス

以前、単色のLEDマトリクスをGR KURUMIから操作してみましたが、今回はフルカラーです。

Arduinoでよく使われるTLC5940というLED用PWMドライバを使ったのですが、GR KURUMIの方の処理速度の問題で、ちらつきを完全になくすことができませんでした。なので、表示処理で素早く点灯色を切り替えて、ちらつきか意図的なものかわかりづらくしてます。笑

それにしても、駅の電光掲示板とか、どんな制御してるんでしょうねえ。びしっと表示されててスクロールまでするので本当にすごいと思います。笑

表示内容はまたもやライフゲームです。

以下、ソースです。

/*GR-KURUMI Sketch Template Version: V1.00*/
#include <RLduino78.h>

#define NUM_5940    2

#define GSCLK_PIN   3

#define COM0_PIN    4
#define COM1_PIN    5
#define COM2_PIN    6

#define VPRG_PIN    7
#define BLANK_PIN   8
#define XLAT_PIN    9

#define SIN_PIN     11
#define SCLK_PIN    13

//void myisr( void );
void set_dc( void );
void set_gs( void );
void proc_gs( void );
void proc_update(unsigned long u32ms);
void disp_update( void );
void set_gsval( void );
void set_row( void );
void get_temp( unsigned long u32ms );
void lifegame( void );
void proc_color( void );

int gsupdate = 0;
int dispindex = 0;

byte dcval[NUM_5940][16] = {
    {0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30},
    {0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30,
    0x30, 0x30, 0x30, 0x30},
};

word gsval[NUM_5940][16];

typedef unsigned long RGB;

#define GetRED(x) (byte)(((x)>>16)&0xff)
#define GetGREEN(x) (byte)(((x)>>8)&0xff)
#define GetBLUE(x) (byte)((x)&0xff)

#define SetRGB(r,g,b) (((r)<<16)|((g)<<8)|(b))
RGB dots[8][8] = {
    { 0x000000, 0x000000, 0x000000, 0xFF8811, 0xFF8811, 0x000000, 0x000000, 0x000000 },
    { 0x000000, 0x000000, 0xFF8811, 0x000000, 0x000000, 0xFF8811, 0x000000, 0x000000 },
    { 0x000000, 0xFF8811, 0x000000, 0x000000, 0x000000, 0x000000, 0xFF8811, 0x000000 },
    { 0xFF8811, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xFF8811 },
    { 0xFF8811, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xFF8811 },
    { 0x000000, 0xFF8811, 0x000000, 0x000000, 0x000000, 0x000000, 0xFF8811, 0x000000 },
    { 0x000000, 0x000000, 0xFF8811, 0x000000, 0x000000, 0xFF8811, 0x000000, 0x000000 },
    { 0x000000, 0x000000, 0x000000, 0xFF8811, 0xFF8811, 0x000000, 0x000000, 0x000000 }
};    

typedef struct {
  byte red;
  byte green;
  byte blue;
} s_dir_colors;
s_dir_colors dir_colors;

int row_index = 0;
int current_temp = 0;

// the setup routine runs once when you press reset:
void setup() {
  int i, j;

  row_index = 0;
  gsupdate = 0;
  dispindex = 0;

  dir_colors.red = 1;
  dir_colors.green = 0;
  dir_colors.blue = 0;

  for( i = 0; i < NUM_5940; i ++ ){
    for( j = 0; j < 16; j ++ ){
      gsval[i][j] = 0;
    }
  }

  pinMode(COM0_PIN, OUTPUT);
  pinMode(COM1_PIN, OUTPUT);
  pinMode(COM2_PIN, OUTPUT);

  pinMode(VPRG_PIN, OUTPUT);
  pinMode(BLANK_PIN, OUTPUT);
  pinMode(XLAT_PIN, OUTPUT);        // SS(STCP)

  pinMode(SIN_PIN, OUTPUT);
  pinMode(SCLK_PIN, OUTPUT);

  pinMode(GSCLK_PIN, OUTPUT);

  digitalWrite(COM0_PIN, LOW);
  digitalWrite(COM1_PIN, LOW);
  digitalWrite(COM2_PIN, LOW);

  digitalWrite(VPRG_PIN, HIGH);
  digitalWrite(BLANK_PIN, HIGH);
  digitalWrite(XLAT_PIN, LOW);

  digitalWrite(GSCLK_PIN, LOW);

  // start work
  set_dc();

  gsupdate = 1;
  attachCyclicHandler(0, get_temp, 3005);
  attachCyclicHandler(1, proc_update, 1000);
}

// the loop routine runs over and over again forever:
void loop() {
  // check update
  disp_update();        // update

  // set row
  set_row();

  // set grayscale data
  set_gs();

  proc_gs();
  
  // increment row
  row_index = ( row_index + 1 ) & 0x7;
}

void get_temp( unsigned long u32ms )
{
  current_temp = getTemperature( TEMP_MODE_CELSIUS );
}

void set_dc( void )
{
  int i = 0;
  int j = 0;
  byte k = 0;

  // Dot Correction
  noInterrupts();

  P0.BIT.bit0 = 1;  // VPRG
  P1.BIT.bit3 = 0;  // XLAT

  P7.BIT.bit0 = 0;  // SCLK

  for( i = 0; i < NUM_5940; i ++  ){
    for( j = 0; j < 16; j ++ ){
      for( k = 0x20; k != 0x00; k >>= 1 ){
        P7.BIT.bit2 = ( ( dcval[i][j] & k ) == 0 ) ? 0 : 1;  // SIN

        P7.BIT.bit0 = 1;  // SCLK
        P7.BIT.bit0 = 0;  // SCLK
      }
    }
  }

  P1.BIT.bit3 = 1;  // XLAT
  P1.BIT.bit3 = 0;  // XLAT

  interrupts();
}

void set_gs( void )
{
  int i = 0;
  int j = 0;
  word k = 0;

  // Gray Scale
  set_gsval();

  noInterrupts();

  P0.BIT.bit0 = 0;  // VPRG

  P1.BIT.bit3 = 0;  // XLAT
  P0.BIT.bit1 = 1;  // BLANK
  P7.BIT.bit0 = 0;  // SCLK

  for( i = 1; i >= 0; i -- ){
    for( j = 0; j < 16; j ++ ){
      for( k = 0x0800; k != 0x0000; k >>= 1 ){
        P7.BIT.bit2 = ( ( gsval[i][j] & k ) == 0 ) ? 0 : 1;  // SIN
        
        P7.BIT.bit0 = 1;  // SCLK
        P7.BIT.bit0 = 0;  // SCLK
      }
    }
  }

  P1.BIT.bit3 = 1;  // XLAT
  P1.BIT.bit3 = 0;  // XLAT

  P7.BIT.bit0 = 1;  // SCLK
  P7.BIT.bit0 = 0;  // SCLK

  interrupts();
}

void proc_gs( void )
{
  int i = 0;

  noInterrupts();

  P0.BIT.bit1 = 0;  // BLANK

  P1.BIT.bit6 = 0;  // GSCLK

  for( i = 0; i < 4096; i ++ ){
    P1.BIT.bit6 = 1;  // GSCLK
    P1.BIT.bit6 = 0;  // GSCLK
  }

  P0.BIT.bit1 = 1;  // BLANK
  P0.BIT.bit1 = 0;  // BLANK

  interrupts();
}

void set_row( void )
{
  // set ROW
  noInterrupts();

  switch( row_index ){
    case 0:
      P3.BIT.bit1 = 0;  // COM0
      P1.BIT.bit5 = 0;  // COM1
      P1.BIT.bit0 = 0;  // COM2
      break;
      
    case 1:
      P3.BIT.bit1 = 1;  // COM0
      P1.BIT.bit5 = 0;  // COM1
      P1.BIT.bit0 = 0;  // COM2
      break;

    case 2:
      P3.BIT.bit1 = 0;  // COM0
      P1.BIT.bit5 = 1;  // COM1
      P1.BIT.bit0 = 0;  // COM2
      break;

    case 3:
      P3.BIT.bit1 = 1;  // COM0
      P1.BIT.bit5 = 1;  // COM1
      P1.BIT.bit0 = 0;  // COM2
      break;

    case 4:
      P3.BIT.bit1 = 0;  // COM0
      P1.BIT.bit5 = 0;  // COM1
      P1.BIT.bit0 = 1;  // COM2
      break;

    case 5:
      P3.BIT.bit1 = 1;  // COM0
      P1.BIT.bit5 = 0;  // COM1
      P1.BIT.bit0 = 1;  // COM2
      break;

    case 6:
      P3.BIT.bit1 = 0;  // COM0
      P1.BIT.bit5 = 1;  // COM1
      P1.BIT.bit0 = 1;  // COM2
      break;

    case 7:
      P3.BIT.bit1 = 1;  // COM0
      P1.BIT.bit5 = 1;  // COM1
      P1.BIT.bit0 = 1;  // COM2
      break;
  
    default:
      break;
  }
  interrupts();
}

void proc_update( unsigned long u32ms )
{
  gsupdate = 1;
}

void set_gsval( void )
{
  /* set gsval */
  gsval[0][0] = GetRED(dots[row_index][5]) * 16;
  gsval[0][1] = GetBLUE(dots[row_index][4]) * 16;
  gsval[0][2] = GetGREEN(dots[row_index][4]) * 16;
  gsval[0][3] = GetRED(dots[row_index][4]) * 16;
  gsval[0][4] = GetBLUE(dots[row_index][3]) * 16;
  gsval[0][5] = GetGREEN(dots[row_index][3]) * 16;
  gsval[0][6] = GetRED(dots[row_index][3]) * 16;
  gsval[0][7] = GetBLUE(dots[row_index][2]) * 16;
  gsval[0][8] = GetGREEN(dots[row_index][2]) * 16;
  gsval[0][9] = GetRED(dots[row_index][2]) * 16;
  gsval[0][10] = GetBLUE(dots[row_index][1]) * 16;
  gsval[0][11] = GetGREEN(dots[row_index][1]) * 16;
  gsval[0][12] = GetRED(dots[row_index][1]) * 16;
  gsval[0][13] = GetBLUE(dots[row_index][0]) * 16;
  gsval[0][14] = GetGREEN(dots[row_index][0]) * 16;
  gsval[0][15] = GetRED(dots[row_index][0]) * 16;

  gsval[1][0] = 0;
  gsval[1][1] = 0;
  gsval[1][2] = 0;
  gsval[1][3] = 0;
  gsval[1][4] = 0;
  gsval[1][5] = 0;
  gsval[1][6] = 0;
  gsval[1][7] = 0;
  gsval[1][8] = GetBLUE(dots[row_index][7]) * 16;
  gsval[1][9] = GetGREEN(dots[row_index][7]) * 16;
  gsval[1][10] = GetRED(dots[row_index][7]) * 16;
  gsval[1][11] = GetBLUE(dots[row_index][6]) * 16;
  gsval[1][12] = GetGREEN(dots[row_index][6]) * 16;
  gsval[1][13] = GetRED(dots[row_index][6]) * 16;
  gsval[1][14] = GetBLUE(dots[row_index][5]) * 16;
  gsval[1][15] = GetGREEN(dots[row_index][5]) * 16;
}

void disp_update( void )
{
  if( gsupdate == 1 ){
    lifegame();
    gsupdate = 0;
  }
  else{
    proc_color();
  }
}  
void lifegame( void )
{
  int y, x;
  int num = 0;
  RGB work[8][8];
    
  for(y=0; y<8; y++){
    for(x=0; x<8; x++){
      work[y][x] = dots[y][x];
    }
  }

  for(y=0; y<8; y++){
    for(x=0; x<8; x++){
      num = 0;
            
      /* count around */
      if( x != 0 ){
        if( dots[y][x-1] != 0 ){
          num ++;
        }
      }
            
      if( x != 7 ){
        if( dots[y][x+1] != 0 ){
          num ++;
        }                    
      }
            
      if( y != 0 ){
        if( dots[y-1][x] != 0 ){
          num ++;
        }
        if( x != 0 ){
          if( dots[y-1][x-1] != 0 ){
            num ++;
          }
        }
        if( x != 7 ){
          if( dots[y-1][x+1] != 0 ){
            num ++;
          }
        }
      }                    

      if( y != 7 ){
        if( dots[y+1][x] != 0 ){
          num ++;
        }
        if( x != 0 ){
          if( dots[y+1][x-1] != 0 ){
            num ++;
          }
        }
        if( x != 7 ){
          if( dots[y+1][x+1] != 0 ){
            num ++;
          }
        }
      }                    

      /* decide */
      if( dots[y][x] == 0 ){
        if( num == 3 ){
          work[y][x] = 0xFF8811;
        }
      }
      else{        
        if( ( num != 2 ) && ( num != 3 ) ){
          work[y][x] = 0;
        }
      }
    }
  }
  for( y=0; y<8; y++ ){
    for( x=0; x<8; x++ ){
      dots[y][x] = work[y][x];
    }
  }
}

void proc_color( void )
{
  int y, x;
  byte tmpred;
  byte tmpgreen;
  byte tmpblue;
  
  for( y=0; y<8; y++ ){
    for( x=0; x<8; x++ ){
      if( dots[y][x] != 0 ){
        tmpred = GetRED( dots[y][x] );
        tmpgreen = GetGREEN( dots[y][x] );
        tmpblue = GetBLUE( dots[y][x] );
         
        if( dir_colors.red == 0 ){
          tmpred = ( tmpred + 0x11 ) & 0xff;
          if( tmpred == 0xff ){
            dir_colors.red = 1;
          }
        }
        else{
          tmpred = ( tmpred - 0x11 ) & 0xff;
          if( tmpred == 0x11 ){
            dir_colors.red = 0;
          }
        }

        if( dir_colors.green == 0 ){
          tmpgreen = ( tmpgreen + 0x11 ) & 0xff;
          if( tmpgreen== 0xff ){
            dir_colors.green = 1;
          }
        }
        else{
          tmpgreen = ( tmpgreen - 0x11 ) & 0xff;
          if( tmpgreen == 0x11 ){
            dir_colors.green = 0;
          }
        }

        if( dir_colors.blue == 0 ){
          tmpblue= ( tmpblue + 0x11 ) & 0xff;
          if( tmpblue == 0xff ){
            dir_colors.green = 1;
          }
        }
        else{
          tmpblue = ( tmpblue - 0x11 ) & 0xff;
          if( tmpblue == 0x11 ){
            dir_colors.blue= 0;
          }
        }
        dots[y][x] = SetRGB( (RGB)tmpred, (RGB)tmpgreen, (RGB)tmpblue );
      }
    }
  }
}

digitalWriteが遅いので、ポート直接叩くように後から書き換えました。お見苦しいかもしれませんが、ご容赦ください。

オシロスコープ買いました

オシロスコープを買いました。

去年の発売から気になっていたテクトロの「4万円台オシロ」TBS1022です。Amazonで注文したらすぐに届きました。

TBS1000シリーズ > オシロスコープ : テクトロニクス

小さくてかっこいいDSO Quadにも心ひかれたのですが、初心者なのでオープンソースハードというのに恐怖(?)を感じまして、ちょっと値段は高くなりますが安心感のあるテクトロを選んだ次第です。

ポケットオシロ DSO Quad - ネット販売

オシロ自体は仕事でたまに使うのですが、設定などはハード屋さんにお願いしてしまうダメソフト屋です。涙)

とりあえず、GR KURUMIから出てくるIOの波形を見たりして楽しんでいます。


https://docs.google.com/file/d/0B9mpDLlbvvN8NkthbFMyTGJhaEE/edit?usp=sharing


GR KURUMIのoutputClock関数で出力した2MHzのパルス

(画像貼りやすいブログに移転したい…泣)