Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 11 months ago.
繰り返しのプログラム
パターン1から3を順番に点灯するのを100回繰り返す動作を実行したあと パターン4から6を同じく順番に点灯し100回繰り返したい場合はどのようなプログラムになりますでしょうか
#include "mbed.h"
Ticker flipper;
BusOut Col(dp3,dp6,dp7,dp8,dp9,dp10,dp11,dp12);
BusOut Row(dp15,dp16,dp17,dp18,dp19,dp20,dp21,dp22);
int select;
void flip()
{
uint8_t pt[][8] = {
{0x90,0x94,0xA4,0x24,0x28,0x48,0x48,0x50}, //パターン1
{0x00,0x00,0x80,0x04,0x20,0x00,0x08,0x50}, //パターン2
{0x00,0x80,0x84,0x24,0x20,0x08,0x58,0x50}, //パターン3
};
static int col = 0;
static int puttern = 0;
static int change = 0;
Row = 0;
Col = pt[puttern][col];
Row = 1 << col;
col++;
col %=8;
change--;
if(change <= 0) {
// パターン3まで行ったら実行する関数を切り替える
if(puttern == 2) select = 1;
// パターンを切り替える
puttern++;
puttern %= sizeof(pt) / sizeof(*pt);
// 次に切り替えるまでの処理回数をセットする
change = 1;
}
}
void flip2()
{
uint8_t pt[][8] = {
{0x48,0x50,0x90,0x94,0xA4,0x24,0x28,0x48}, //パターン4
{0x08,0x40,0x00,0x00,0x80,0x04,0x20,0x00}, //パターン5
{0x48,0x40,0x00,0x80,0x84,0x24,0x20,0x08}, //パターン6
};
static int col = 0;
static int puttern = 0;
static int change = 0;
Row = 0;
Col = pt[puttern][col];
Row = 1 << col;
col++;
col %=8;
change--;
if(change <= 0) {
// 最後のパターンまで行ったら実行する関数を切り替える
if(puttern == (int)(sizeof(pt)/sizeof(*pt) - 1)) select = 0;
// パターンを切り替える
puttern++;
puttern %= sizeof(pt) / sizeof(*pt);
// 次に切り替えるまでの処理回数をセットする
change = 1;
}
}
void flipSelector()
{
switch(select) {
case 0: flip(); break;
case 1: flip2(); break;
}
}
int main()
{
select = 0;
flipper.attach(&flipSelector,0.002);
while(1) {
}
}