mbedで2つのプログラム実行

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
uuu

mbedで2つのプログラム実行

#1

投稿記事 by uuu » 7年前

mbedを使って、2つのプログラム(flip1とflip2)を
順番に実行させたいのですが、flip2のみ実行されてしまい
解決方法が分からず困っておりますので、どなたか分かる方
教えて頂けないでしょうか。よろしくお願いいたします。

コード:

#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);

void flip()
{
    uint8_t pt[][8] = {
    {0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン1
    {0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン2
    {0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン3
    {0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン4
    {0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00}, //パターン5
    {0x00,0x40,0x40,0x40,0x00,0x00,0x00,0x00}, //パターン6
    {0x00,0x00,0x40,0x40,0x40,0x00,0x00,0x00}, //パターン7
    {0x40,0x00,0x00,0x40,0x40,0x40,0x00,0x00}, //パターン8
    {0x00,0x40,0x00,0x00,0x40,0x40,0x40,0x00}, //パターン9
};
    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) {
        
        // パターンを切り替える
        puttern++;
        puttern %= sizeof(pt) / sizeof(*pt);
        
        // 次に切り替えるまでの処理回数をセットする
        change = 100;
    }
}    
    //{0x00,0x00,0x40,0x00,0x00,0x40,0x40,0x40}, //パターン10

void flip2()
{
    uint8_t pt[][8] = {
    {0x00,0x00,0x00,0x40,0x00,0x00,0x40,0x40}, //パターン11
    {0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x40,}, //パターン12
    {0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,}, //パターン13
    {0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,}, //パターン14
    {0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x40,}, //パターン15
    {0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,}, //パターン16
    {0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,}, //パターン17
    {0x00,0x08,0x08,0x08,0x00,0x00,0x00,0x00,}, //パターン18
    {0x00,0x00,0x08,0x08,0x08,0x00,0x00,0x00,}, //パターン19
    {0x08,0x00,0x00,0x08,0x08,0x08,0x00,0x00,}, //パターン20    
    {0x00,0x08,0x00,0x00,0x08,0x08,0x08,0x00,}, //パターン21
    {0x00,0x00,0x08,0x00,0x00,0x08,0x08,0x08,}, //パターン22
    {0x00,0x00,0x00,0x08,0x00,0x00,0x08,0x08,}, //パターン23
    {0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x08,}, //パターン24
    {0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,}, //パターン25
    {0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,}, //パターン26
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,}, //パターン27
};
    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) {
        
        // パターンを切り替える
        puttern++;
        puttern %= sizeof(pt) / sizeof(*pt);
        
        // 次に切り替えるまでの処理回数をセットする
        change = 100;
    }
}

int main()
{
    flipper.attach(&flip,0.002);  
    flipper.attach(&flip2,0.002);
    
   while(1) {
    }
}

アバター
みけCAT
記事: 6734
登録日時: 13年前
住所: 千葉県
連絡を取る:

Re: mbedで2つのプログラム実行

#2

投稿記事 by みけCAT » 7年前

uuu さんが書きました:解決方法が分からず困っておりますので、どなたか分かる方
教えて頂けないでしょうか。
多分、いい感じにコードを書き換え、コンパイルして書き込んで実行すればいいでしょう。
uuu さんが書きました:2つのプログラム(flip1とflip2)を
順番に実行させたいのですが
「順番に実行」とは、具体的にどのようなタイミング/スケジュールで実行させたいのですか?
例えば、

コード:

void flipAll()
{
    flip();
    flip2();
}

int main()
{
    flipper.attach(&flipAll,0.002);
    
   while(1) {
    }
}
みたいなのも「順番に実行」ですよね。
(flip1はflipの間違いであると仮定しました)
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

uuu

Re: mbedで2つのプログラム実行

#3

投稿記事 by uuu » 7年前

>「順番に実行」とは、具体的にどのようなタイミング/スケジュールで実行させたいのですか?

flipの動作(パターン1~9まで実行)した後に
flip2を実行させるようにしたいです。

あんどーなつ
記事: 171
登録日時: 7年前
連絡を取る:

Re: mbedで2つのプログラム実行

#4

投稿記事 by あんどーなつ » 7年前

uuu さん

疲れました。これXY問題です。
あなたの最終ゴールをまとめてみてください。

[例]

・8x8のマス目にA, B, C, D, Eという文字を1秒づつ表示し、それを交互に繰り返したい
・8x8のマス目に棒人間の絵をかいて、毎秒10フレーム位でアニメーションさせたい

など。

アバター
みけCAT
記事: 6734
登録日時: 13年前
住所: 千葉県
連絡を取る:

Re: mbedで2つのプログラム実行

#5

投稿記事 by みけCAT » 7年前

uuu さんが書きました:flipの動作(パターン1~9まで実行)した後に
flip2を実行させるようにしたいです。
flipをパターン9まで実行した後にflip2を実行させるようなコードにすればいいでしょう。

コード:

#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] = {
    {0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン1
    {0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン2
    {0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン3
    {0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン4
    {0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00}, //パターン5
    {0x00,0x40,0x40,0x40,0x00,0x00,0x00,0x00}, //パターン6
    {0x00,0x00,0x40,0x40,0x40,0x00,0x00,0x00}, //パターン7
    {0x40,0x00,0x00,0x40,0x40,0x40,0x00,0x00}, //パターン8
    {0x00,0x40,0x00,0x00,0x40,0x40,0x40,0x00}, //パターン9
};
    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) {
        
        // パターン9まで行ったら実行する関数を切り替える
        if(puttern == 8) select = 1;
        
        // パターンを切り替える
        puttern++;
        puttern %= sizeof(pt) / sizeof(*pt);
        
        // 次に切り替えるまでの処理回数をセットする
        change = 100;
    }
}    
    //{0x00,0x00,0x40,0x00,0x00,0x40,0x40,0x40}, //パターン10

void flip2()
{
    uint8_t pt[][8] = {
    {0x00,0x00,0x00,0x40,0x00,0x00,0x40,0x40}, //パターン11
    {0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x40,}, //パターン12
    {0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,}, //パターン13
    {0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,}, //パターン14
    {0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x40,}, //パターン15
    {0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,}, //パターン16
    {0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,}, //パターン17
    {0x00,0x08,0x08,0x08,0x00,0x00,0x00,0x00,}, //パターン18
    {0x00,0x00,0x08,0x08,0x08,0x00,0x00,0x00,}, //パターン19
    {0x08,0x00,0x00,0x08,0x08,0x08,0x00,0x00,}, //パターン20    
    {0x00,0x08,0x00,0x00,0x08,0x08,0x08,0x00,}, //パターン21
    {0x00,0x00,0x08,0x00,0x00,0x08,0x08,0x08,}, //パターン22
    {0x00,0x00,0x00,0x08,0x00,0x00,0x08,0x08,}, //パターン23
    {0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x08,}, //パターン24
    {0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,}, //パターン25
    {0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,}, //パターン26
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,}, //パターン27
};
    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) {
        
        // パターンを切り替える
        puttern++;
        puttern %= sizeof(pt) / sizeof(*pt);
        
        // 次に切り替えるまでの処理回数をセットする
        change = 100;
    }
}

void flipSelector()
{
    switch(select) {
        case 0: flip(); break;
        case 1: flip2(); break;
    }
}

int main()
{
    select = 0;
    flipper.attach(&flipSelector,0.002);
    
   while(1) {
    }
}
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

uuu

Re: mbedで2つのプログラム実行

#6

投稿記事 by uuu » 7年前

みけCATさま

ありがとうございます。
実行できましたが、一点問題がありました。

filip2が終わった後に、flipが始まらずflip2でループしてしまいました。
解決策はありますか
下記のように変更しましたが、ダメでした。

コード:

#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] = {
    {0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン1
    {0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン2
    {0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン3
    {0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00}, //パターン4
    {0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00}, //パターン5
    {0x00,0x40,0x40,0x40,0x00,0x00,0x00,0x00}, //パターン6
    {0x00,0x00,0x40,0x40,0x40,0x00,0x00,0x00}, //パターン7
    {0x40,0x00,0x00,0x40,0x40,0x40,0x00,0x00}, //パターン8
    {0x00,0x40,0x00,0x00,0x40,0x40,0x40,0x00}, //パターン9
};
    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) {
        
        // パターン9まで行ったら実行する関数を切り替える
        if(puttern == 8) select = 1;
        
        // パターンを切り替える
        puttern++;
        puttern %= sizeof(pt) / sizeof(*pt);
        
        // 次に切り替えるまでの処理回数をセットする
        change = 100;
    }
}    
 
void flip2()
{
    uint8_t pt[][8] = {
    {0x00,0x00,0x40,0x00,0x00,0x40,0x40,0x40}, //パターン10
    {0x00,0x00,0x00,0x40,0x00,0x00,0x40,0x40}, //パターン11
    {0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x40,}, //パターン12
    {0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,}, //パターン13
    {0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,}, //パターン14
    {0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x40,}, //パターン15
    {0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,}, //パターン16
    {0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,}, //パターン17
    {0x00,0x08,0x08,0x08,0x00,0x00,0x00,0x00,}, //パターン18
    {0x00,0x00,0x08,0x08,0x08,0x00,0x00,0x00,}, //パターン19
    {0x08,0x00,0x00,0x08,0x08,0x08,0x00,0x00,}, //パターン20    
    {0x00,0x08,0x00,0x00,0x08,0x08,0x08,0x00,}, //パターン21
    {0x00,0x00,0x08,0x00,0x00,0x08,0x08,0x08,}, //パターン22
    {0x00,0x00,0x00,0x08,0x00,0x00,0x08,0x08,}, //パターン23
    {0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x08,}, //パターン24
    {0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,}, //パターン25
    {0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,}, //パターン26
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,}, //パターン27
};
    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) {
        

        // パターン27まで行ったら実行する関数を切り替える
        if(puttern == 26) select = 0;
        
        // パターンを切り替える
        puttern++;
        puttern %= sizeof(pt) / sizeof(*pt);
        
        // 次に切り替えるまでの処理回数をセットする
        change = 100;
    }
}
 
void flipSelector()
{
    switch(select) {
        case 0: flip(); break;
        case 1: flip2(); break;
    }
}
 
int main()
{
    select = 0;
    flipper.attach(&flipSelector,0.002);
    
   while(1) {
    }
}

アバター
みけCAT
記事: 6734
登録日時: 13年前
住所: 千葉県
連絡を取る:

Re: mbedで2つのプログラム実行

#7

投稿記事 by みけCAT » 7年前

flip2の最後のパターンが終わったらflipを実行するモードに戻すようにするといいでしょう。

コード:

if(puttern == 26) select = 0;

コード:

if(puttern == 17) select = 0;
とするか、マジックナンバーを避けて

コード:

if(puttern == (int)(sizeof(pt)/sizeof(*pt) - 1)) select = 0;
とするといいでしょう。
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

uuu

Re: mbedで2つのプログラム実行

#8

投稿記事 by uuu » 7年前

うまくいきました
ありがとうございました。

閉鎖

“C言語何でも質問掲示板” へ戻る