sample ploglam
Dependencies: SDFileSystem mbed
Fork of cansat by
main.cpp@0:649fc30be6ec, 2016-02-29 (annotated)
- Committer:
- Nike3221
- Date:
- Mon Feb 29 11:10:31 2016 +0000
- Revision:
- 0:649fc30be6ec
- Child:
- 1:fa44a6246bcc
cansat
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nike3221 | 0:649fc30be6ec | 1 | #include "mbed.h" |
Nike3221 | 0:649fc30be6ec | 2 | #include "SDFileSystem.h" |
Nike3221 | 0:649fc30be6ec | 3 | |
Nike3221 | 0:649fc30be6ec | 4 | Ticker timer; |
Nike3221 | 0:649fc30be6ec | 5 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board |
Nike3221 | 0:649fc30be6ec | 6 | Serial gp(p28, p27); // tx, rx |
Nike3221 | 0:649fc30be6ec | 7 | Serial pc(USBTX, USBRX); // tx, rx |
Nike3221 | 0:649fc30be6ec | 8 | PwmOut moterl(p21);//左モーター |
Nike3221 | 0:649fc30be6ec | 9 | PwmOut moterr(p22);//右モーター |
Nike3221 | 0:649fc30be6ec | 10 | DigitalOut led1(LED1); |
Nike3221 | 0:649fc30be6ec | 11 | DigitalOut fet3(p23);//ニクロム線 |
Nike3221 | 0:649fc30be6ec | 12 | DigitalOut led2(LED2); |
Nike3221 | 0:649fc30be6ec | 13 | DigitalOut led3(LED3); |
Nike3221 | 0:649fc30be6ec | 14 | DigitalOut led4(LED4); |
Nike3221 | 0:649fc30be6ec | 15 | DigitalOut janpa1(p19);//パラシュートの開きを検知 |
Nike3221 | 0:649fc30be6ec | 16 | DigitalIn janpa2(p20);//パラシュートの開きを検知 |
Nike3221 | 0:649fc30be6ec | 17 | int gosa; |
Nike3221 | 0:649fc30be6ec | 18 | |
Nike3221 | 0:649fc30be6ec | 19 | char gpsc[100]; |
Nike3221 | 0:649fc30be6ec | 20 | int a,b,c,d; |
Nike3221 | 0:649fc30be6ec | 21 | int i=0; |
Nike3221 | 0:649fc30be6ec | 22 | |
Nike3221 | 0:649fc30be6ec | 23 | void gps() |
Nike3221 | 0:649fc30be6ec | 24 | { |
Nike3221 | 0:649fc30be6ec | 25 | led1 = 1; |
Nike3221 | 0:649fc30be6ec | 26 | |
Nike3221 | 0:649fc30be6ec | 27 | printf("Hello World!\n"); |
Nike3221 | 0:649fc30be6ec | 28 | |
Nike3221 | 0:649fc30be6ec | 29 | mkdir("/sd/mydir", 0777); |
Nike3221 | 0:649fc30be6ec | 30 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "a"); |
Nike3221 | 0:649fc30be6ec | 31 | if(fp == NULL) { |
Nike3221 | 0:649fc30be6ec | 32 | error("Could not open file for write\n"); |
Nike3221 | 0:649fc30be6ec | 33 | } |
Nike3221 | 0:649fc30be6ec | 34 | |
Nike3221 | 0:649fc30be6ec | 35 | led1 = 0; |
Nike3221 | 0:649fc30be6ec | 36 | led2 = 1; |
Nike3221 | 0:649fc30be6ec | 37 | while(i!=50) |
Nike3221 | 0:649fc30be6ec | 38 | { fputc(gp.getc(),fp); |
Nike3221 | 0:649fc30be6ec | 39 | i++; } |
Nike3221 | 0:649fc30be6ec | 40 | fputc(a,fp); |
Nike3221 | 0:649fc30be6ec | 41 | |
Nike3221 | 0:649fc30be6ec | 42 | fclose(fp); |
Nike3221 | 0:649fc30be6ec | 43 | |
Nike3221 | 0:649fc30be6ec | 44 | led1 = 0; |
Nike3221 | 0:649fc30be6ec | 45 | } |
Nike3221 | 0:649fc30be6ec | 46 | |
Nike3221 | 0:649fc30be6ec | 47 | |
Nike3221 | 0:649fc30be6ec | 48 | void start() |
Nike3221 | 0:649fc30be6ec | 49 | { |
Nike3221 | 0:649fc30be6ec | 50 | janpa1=1; |
Nike3221 | 0:649fc30be6ec | 51 | while(janpa2 == 1) |
Nike3221 | 0:649fc30be6ec | 52 | { led4 = 0; |
Nike3221 | 0:649fc30be6ec | 53 | led3 = 1;}//2 |
Nike3221 | 0:649fc30be6ec | 54 | |
Nike3221 | 0:649fc30be6ec | 55 | } |
Nike3221 | 0:649fc30be6ec | 56 | |
Nike3221 | 0:649fc30be6ec | 57 | |
Nike3221 | 0:649fc30be6ec | 58 | |
Nike3221 | 0:649fc30be6ec | 59 | void nikuromu() |
Nike3221 | 0:649fc30be6ec | 60 | { |
Nike3221 | 0:649fc30be6ec | 61 | led4=1; |
Nike3221 | 0:649fc30be6ec | 62 | fet3=1;//3 |
Nike3221 | 0:649fc30be6ec | 63 | wait(60);//焼き切り時間 |
Nike3221 | 0:649fc30be6ec | 64 | led4=0; |
Nike3221 | 0:649fc30be6ec | 65 | led3=0; |
Nike3221 | 0:649fc30be6ec | 66 | led2=1;//4 |
Nike3221 | 0:649fc30be6ec | 67 | } |
Nike3221 | 0:649fc30be6ec | 68 | |
Nike3221 | 0:649fc30be6ec | 69 | void moter() { |
Nike3221 | 0:649fc30be6ec | 70 | while(1) |
Nike3221 | 0:649fc30be6ec | 71 | { |
Nike3221 | 0:649fc30be6ec | 72 | float offset=0.0; |
Nike3221 | 0:649fc30be6ec | 73 | float offset2=0.0; |
Nike3221 | 0:649fc30be6ec | 74 | moterl.period(0.02); // 周期 |
Nike3221 | 0:649fc30be6ec | 75 | moterr.period(0.02); |
Nike3221 | 0:649fc30be6ec | 76 | moterl.pulsewidth(0.08); // servo position determined by a pulsewidth between 1-2ms |
Nike3221 | 0:649fc30be6ec | 77 | moterr.pulsewidth(0.08); //パルス幅 |
Nike3221 | 0:649fc30be6ec | 78 | |
Nike3221 | 0:649fc30be6ec | 79 | |
Nike3221 | 0:649fc30be6ec | 80 | } |
Nike3221 | 0:649fc30be6ec | 81 | led2=led3=led4=1; |
Nike3221 | 0:649fc30be6ec | 82 | wait(1.0); |
Nike3221 | 0:649fc30be6ec | 83 | led2=led3=led4=0; |
Nike3221 | 0:649fc30be6ec | 84 | wait(1.0); |
Nike3221 | 0:649fc30be6ec | 85 | led2=led3=led4=1; |
Nike3221 | 0:649fc30be6ec | 86 | } |
Nike3221 | 0:649fc30be6ec | 87 | |
Nike3221 | 0:649fc30be6ec | 88 | int main() |
Nike3221 | 0:649fc30be6ec | 89 | { |
Nike3221 | 0:649fc30be6ec | 90 | gp.baud(9600); |
Nike3221 | 0:649fc30be6ec | 91 | timer.attach(&gps, 2.0);//割り込み |
Nike3221 | 0:649fc30be6ec | 92 | led4 = 1; |
Nike3221 | 0:649fc30be6ec | 93 | start(); |
Nike3221 | 0:649fc30be6ec | 94 | wait(60);//落下中 |
Nike3221 | 0:649fc30be6ec | 95 | nikuromu(); |
Nike3221 | 0:649fc30be6ec | 96 | moter(); |
Nike3221 | 0:649fc30be6ec | 97 | |
Nike3221 | 0:649fc30be6ec | 98 | return 0; |
Nike3221 | 0:649fc30be6ec | 99 | } |