手動機 ヌクレオ用のプログラムです

Dependencies:   mbed

Fork of F3RC_syudou_slave_3 by F3RC1班

main.cpp

Committer:
yuto17320508
Date:
2017-08-21
Revision:
0:d0441e7d5ea3
Child:
1:dfabac3b39e9

File content as of revision 0:d0441e7d5ea3:

#include "mbed.h"

Serial pc(USBTX,USBRX);
SPISlave spi(PC_12,PC_11,PC_10,PA_13);
DigitalOut photo_1(PC_2);
DigitalOut photo_2(PC_3);
DigitalOut moter_1(PA_10);
DigitalOut moter_2(PA_2);
DigitalOut cyli_1(PB_5);
DigitalOut cyli_2(PB_3);
DigitalOut cyli_3(PA_10);

int a,b,c,d,e,f,g,h,i,j;

//モーターの出力の設定
double moter_power = 0.7;

int main()
{
    spi.format(16,3);
    spi.frequency(1000000);

    while(1) {

        if(spi.receive()) {

            int a = spi.read() & 0b1;
            int b = (spi.read() & 0b10)>>1;
            int c = (spi.read() & 0b100)>>2;
            int d = (spi.read() & 0b1000)>>3;
            int e = (spi.read() & 0b10000)>>4;
            int f = (spi.read() & 0b100000)>>5;
            int g = (spi.read() & 0b1000000)>>6;
            int h = (spi.read() & 0b10000000)>>7;
            int i = (spi.read() & 0b100000000)>>8;
            int j = (spi.read() & 0b1000000000)>>9;
            pc.printf("a:%d\tb:%d\tc:%d\td:%d\te:%d\tf:%d\tg:%d\th:%d\ti:%d\tj:%d\r\n",a,b,c,d,spi.read());

        }
//フォトトランジスタ1
        if(a == 1) {
            photo_1=1;
        } else {
            photo_1=0;
        }

//フォトトランジスタ2
        if(b == 1) {
            photo_2=1;
        } else {
            photo_2=0;
        }

//腕1 上昇下降
        if(c == 1) {
            moter_1=1;
            moter_2=0;
        } else if(d == 1) {
            moter_1=0;
            moter_2=1;
        } else {
            moter_1=0;
            moter_2=0;
        }

//腕1 開閉
        if(e == 1) {
            cyli_1=1;
        } else if(f == 1) {
            cyli_1=0;
        }

//腕2 上昇下降
        if(g == 1) {
            cyli_2=1;
        } else if(h == 1) {
            cyli_2=0;
        }

//腕2 開閉
        if(i == 1) {
            cyli_3=1;
        } else if(j == 1) {
            cyli_3=0;
        } 
    }

}