I-O DATA DEV2 / Mbed 2 deprecated ud-gs2-hello

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main-rodeoboy.cpp Source File

main-rodeoboy.cpp

00001 #include "mbed.h"
00002 //リレーを介して、ロデオボーイを強モードで動かし続けるためのプログラム
00003 /*
00004    This basic example just shows how to read the ADC internal channels raw values.
00005    Please look in the corresponding device reference manual for a complete
00006    description of how to make a temperature sensor, VBat or Vref measurement.
00007 */
00008 
00009 AnalogIn adc_temp(ADC_TEMP);
00010 AnalogIn adc_vref(ADC_VREF);
00011 Ticker     interrput;
00012 /* UD-GS2 H/W define 
00013  PIO_SWin    PB_4 
00014  PIO_wkup    PA_4 
00015  PIO_enable  PB_0
00016  PIO_intout1 PB_2
00017  PIO_led     PB_5
00018  PIO_v20v    PC_13
00019  PIO_v18v    PH_0
00020  PIO_intout2 PH_1
00021  PIO_spics   PB_12
00022  PIO_battryMonEn   PA_5
00023 */
00024 
00025 RawSerial         pc(PA_9, PA_10,115200); //console UART
00026 //LowPowerTicker    interrput;
00027 SPI               STSPI(PB_15, PB_14, PB_13); //mosi,miso,clk
00028 DigitalOut        relay1(PA_11);
00029 DigitalOut        relay2(PA_8);
00030 DigitalOut        STSPICS(PB_12);      
00031 DigitalOut        led(PB_5);
00032 int initLIS3DH();
00033 int read3axes(short *tx,short *ty,short *tz); //read3axesという関数がmbedにあって、それを呼び出してる
00034 int readTemp(short *tmp);
00035 int tmr = 0;
00036 int cnt = 0;
00037 int i = 0;
00038 int j = 0;
00039 int m = 0;
00040 int n = 0;
00041 
00042 void timer(){ //xの値で動いていないと判断したとき
00043    tmr++;
00044    if(tmr > 15)
00045    {
00046        tmr = 0;
00047        
00048        for(i=0;i<2; i++)// 強モードまでボタン3回押す。
00049        {
00050          relay1 = !relay1;
00051          wait(1);
00052        }
00053        wait(2);
00054        for(j=0; j<4; j++)
00055        {
00056          relay2 = !relay2;
00057          wait(0.6);
00058        }
00059    }
00060    
00061 }
00062 
00063 int main()
00064 {
00065     initLIS3DH();
00066     short x,y,z,tmp;
00067     
00068     pc.printf("\nSTM32 ADC internal channels reading example\r\n");
00069     
00070     pc.printf("-----RODEOBOY MODE = HIGH POWER START------\r\n");
00071  
00072     for(m=0;m<2; m++)// 強モードまでボタン3回押す。
00073     {
00074       relay1 = !relay1;
00075       wait(0.5);
00076     }
00077     wait(2);
00078     for(n=0;n<4; n++)// 強モードまでボタン3回押す。
00079     {
00080       relay2 = !relay2;
00081       wait(0.6);
00082     }
00083     
00084     interrput.attach(&timer, 60);//1分ごとに刻み、15分経つとロデオが自動OFF想定なので、そのタイミングで再び動作させる。
00085   
00086     while(1) {
00087 //        pc.printf("ADC Temp = %f\r\n", (adc_temp.read()*100));
00088 //        pc.printf("ADC VRef = %f\r\n", adc_vref.read());         
00089 //        pc.printf("\033[2A");
00090 
00091 
00092         read3axes(&x,&y,&z);
00093         readTemp(&tmp);
00094         pc.printf("x=%d y=%d z=%d \r\n", x,y,z);         //上のread関数とprintfのところにtmpも追加すると、温度も分かります。
00095         pc.printf("x=%f y=%f z=%f\r\n", (float)x/1024.0f,(float)y/1024.0f,(float)z/1024.0f);      
00096         if(z>1050){
00097             cnt++;
00098             pc.printf("/////////count = %d ///////////\r\n",cnt);
00099         }
00100         led = !led;
00101         wait(0.1);
00102     }
00103 }
00104 /*********** porting **************/   
00105 void spiFormat(int b,int m) {
00106    STSPI.format(b,m);  /* 8bit */
00107 }
00108 void spiFrequency(int f){
00109     STSPI.frequency(f); /* 1Mbps */
00110 }
00111 void spiWriteCS(int cs) {
00112     STSPICS=cs;
00113 }
00114 int spiWrite(int wd) {
00115     return ( STSPI.write(wd)); 
00116 }