x 過去ログをみよ
//ssd1306_Sound_Oscilloscope_point2_UNO_1
//インクルド
#include <Arduino.h>
//定義
//GPIO
#define GPIO_RESET_P 2 //RESET=1
#define GPIO_RS_P 17 //RS=0 (A3)
#define GPIO_WR_P 3 //WR=1
#define GPIO_RD_P 16 //RD=1 (A2)
//8bitのGPIOの設定
int DBx[8] = {4, 15, 5, 14, 6, 9, 7, 8};
// GPIO A4 I2Cで使用済み
// GPIO A5 I2Cで使用済み
#define GPIO1(s) digitalWrite(GPIO_RESET_P , s) //RESET
#define GPIO2(s) digitalWrite(GPIO_RS_P , s) //A0
#define GPIO3(s) digitalWrite(GPIO_WR_P , s) //WR
#define GPIO4(s) digitalWrite(GPIO_RD_P , s) //RD
//全体のカラー
int s_color = 0xFFFF; //ハイホワイト
//パラレルポートにデータをセットする。
void GPIO_8BIT(int s)
{
//8bitのGPIOのセット
for (int ee = 0; ee < 8; ee++) {
digitalWrite(DBx[ee], (s >> ee) & 0x01); //DB7
}//for ee
} //GPIO_8BIT
//コマンドの書き込み
void LCD_Write_CMD(int a)
{
GPIO2(0); //A0=0;
GPIO_8BIT(a);//P1=a; data
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
} //LCD_Write_CMD
//データ書き込み
void LCD_Write_Data(int a)
{
GPIO2(1);//A0=1;
GPIO_8BIT(a);//P1=a; data
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
} //LCD_Write_Data
//液晶の初期化処理
void ATM0177B5_ST7735S_Init(void)
{
//---------- ST7735S Reset Sequence --------//
GPIO1(1);//LCD_RESET=1;
delay(1); //Delay 1ms
GPIO1(0);//LCD_RESET=0;
delay(1); //Delay 1ms
GPIO1(1);//LCD_RESET=1;
delay(120); //Delay 120ms
//---------- ST7735S Reset Sequence --------//
LCD_Write_CMD(0x01);//SOFTWARE RESET
delay(50);
LCD_Write_CMD(0x11);//SLEEP OUT
delay(200);
LCD_Write_CMD(0x29);//display on
delay(100);
LCD_Write_CMD(0x3a);//Interface pixel format
LCD_Write_Data(0x05);//16bit mode
delay(100);
LCD_Write_CMD(0x36);//RGB-RGR format
LCD_Write_Data(0x08);//RGB mode
delay(100);
//画面の書き込み開始
LCD_Write_CMD(0x2C); //memory write
GPIO2(1);//A0=1;
delay(2);
} //ATM0177B5_ST7735S_Init
//全体のカラーの変更
void set_color(int color) {
s_color = color;
}//set_color
int SO_X = 0;
int SO_Y = 0;
//パターンRAMの内容を液晶に転送
void Sound_Oscilloscope(int L1,int L2) {
if (SO_Y >= 160) {
//画面の書き込み開始
LCD_Write_CMD(0x2C); //memory write
GPIO2(1);//A0=1;
delay(2);
SO_Y = 0;
//while(1){} //debug
}
//L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1
//L1
GPIO_8BIT( 0xff );
for (int x = 0; x < (L1 ); x++) {
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
}//for
GPIO_8BIT( 0x00 );
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
//GPIO_8BIT( 0xff );
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
GPIO_8BIT( 0xff );//P1=a; data
for (int x = 0; x < (64 - (L1 + 1)); x++) {
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
}//for
// L2 L2 L2 L2 L2 L2 L2 L2 L2 L2 L2 L2 L2 L2
//L1
GPIO_8BIT( 0xff );
for (int x = 0; x < ( L2 ); x++) {
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
}//for
GPIO_8BIT( 0x00 );
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
//GPIO_8BIT( 0xff );
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
GPIO_8BIT( 0xff );//P1=a; data
for (int x = 0; x < (64 - (L2 + 1)); x++) {
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
GPIO3(0);//WRB=0;
GPIO3(1);//WRB=1;
}//for
SO_Y++;
}//Sound_Oscilloscope
//リフレッシュ(画像の再表示)
void refresh() {
Sound_Oscilloscope(0,0);//パターンRAMの反映
}//refresh
//初期化
void setup() {
//ポートのモード設定
//アウトプットモード
pinMode(GPIO_RESET_P, OUTPUT); //REST
pinMode(GPIO_RS_P, OUTPUT); //RS
pinMode(GPIO_WR_P, OUTPUT); //WR
pinMode(GPIO_RD_P, OUTPUT); //RD
//8bit分OUTPUTにする
for (int ee = 0; ee < 8; ee++) {
pinMode(DBx[ee], OUTPUT);
}//for ee
//ポートの初期化
GPIO4(1);//RD=1
GPIO3(0);//WR=0
GPIO2(0);//RS=0
GPIO1(1);//RESET=1
delay(500); //0.5秒待つ
//液晶の初期化処理
ATM0177B5_ST7735S_Init();
} //setup
//メインループ
void loop() {
static int L1 = 0;
L1 = L1 + ( random(16) - 8 );
if( L1 < 0 ) { L1 = 0; } else if ( L1 > 64 ){ L1 = 64;}
//L1 = 32;
static int L2 = 0;
L2 = L2 + ( random(16) - 8 );
if( L2 < 0 ) { L2 = 0; } else if ( L2 > 64 ){ L2 = 64;}
//L1 = 32;
Sound_Oscilloscope(L1,L2); //画面の再表示
//delay(1000); //1秒待つ debug
} //loop