Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:6e40bb2ed99c
- Parent:
- 0:380869d1fc31
--- a/main.cpp Sun Nov 08 12:15:44 2020 +0000
+++ b/main.cpp Tue Nov 10 02:57:19 2020 +0000
@@ -5,6 +5,11 @@
DigitalIn button(USER_BUTTON);
RawSerial pc(PA_2, PA_3,115200 );
+DigitalIn l_button(D4,PullUp);
+DigitalIn r_button(D3,PullUp);
+
+InterruptIn event(USER_BUTTON);
+Ticker interrput;
char bdata[20][20]={
@@ -20,7 +25,7 @@
2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2,
2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2,
2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2,
- 2,0,0,0,0 ,0,0,0,0,1, 1,0,0,0,0 ,0,0,0,0,2,
+ 2,0,0,0,0 ,0,1,0,0,1, 1,0,1,0,0 ,0,0,0,0,2,
2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2,
2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2,
2,0,0,0,0 ,0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,2,
@@ -80,38 +85,78 @@
}
}
+int dx=1;//横移動
+int dy=1;//縦移動
+
+/* GPIO 割り込み */
+void pressed()
+{
+ //pc.printf("Button pressed\n");
+ dx = -dx;//横 動きを逆に
+}
+
+/* タイマー割り込み */
+void intTimer()
+{
+ led = !led;
+}
int main()
{
int i;
int x;
int y;
- int dx=1;
- int dy=1;
-
- clear_all();
+ clear_all(); //画面クリア
+ event.fall(&pressed); //ボタン押した時、 立下りエッジ割り込みの関数設定
+ interrput.attach(&intTimer, 0.5f); //0.5秒タイマーで割り込みの関数設定
pc.printf("\nStart example\n");
- init_bd();
- x=2;
- y=0;
- while(1) {
- if (y>=19) dy=-1;
+ init_bd();//ブロックデータの初期化
+ x=2;//横 初期位置
+ y=0;//縦 初期位置
+ i=0;
+ while(1) {
+ //範囲越え判定
+ if (y>=17) dy=-1;
if (x>=19) dx=-1;
if (y<=0) dy=1;
if (x<=0) dx=1;
+ //移動計算
x=x+dx;
y=y+dy;
- cur_xy(x+1,y+1);
- if (bdata[y][x]==1) {
- bdata[y][x]=0;
- pc.printf(" ");
- pc.printf("\007");
+ cur_xy(x+1,y+1); //カーソル座標設定
+ if (bdata[y][x]==1) { //当たり判定
+ bdata[y][x]=0; //ブロックをなくす
+ pc.printf(" "); //@を消す
+ cur_xy(x+1,y+1);//カーソルを戻す
+ pc.printf("\007");//ベル音
}
+
wait(0.1f);
- if (button==0) dx = -dx;
+ //ボタン操作
+// if (button==0) dx = -dx;
+// dx=0;
+// if (l_button==0) dx= -1;
+// else if (r_button==0) dx= 1;
+ //パドル表示
+ if (x<=1){
+ cur_xy(1,19); //カーソル座標設定
+ pc.printf("HXX ");
+ } else if (x>=17) {
+ cur_xy(17,19); //カーソル座標設定
+ pc.printf(" XXH");
+ } else {
+ cur_xy(x,19);//カーソル
+ pc.printf(" XX ");
+ }
+ cur_xy(x+1,y+1);//カーソルを戻す
+ i++;
+ if (i==100) __disable_irq(); // 禁止
+ else if(i==200) __enable_irq(); // 許可
+
}
+
}