pressure_masuda
Dependencies: SCP1000 SCP1000_Example TextLCD mbed
Fork of SCP1000_Example by
main.cpp@2:479b749065ee, 2013-03-12 (annotated)
- Committer:
- KAME
- Date:
- Tue Mar 12 07:54:43 2013 +0000
- Revision:
- 2:479b749065ee
- Parent:
- 1:6fb7e6fcbb68
pressure_sensor_masuda
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KAME | 2:479b749065ee | 1 | #include "mbed.h" |
KAME | 2:479b749065ee | 2 | #include "SCP1000.h" |
KAME | 2:479b749065ee | 3 | #include "TextLCD.h" |
KAME | 2:479b749065ee | 4 | |
KAME | 2:479b749065ee | 5 | //TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d0-d3 |
KAME | 2:479b749065ee | 6 | |
KAME | 2:479b749065ee | 7 | DigitalOut myled(LED1); |
KAME | 2:479b749065ee | 8 | ADXL345 adx1345(p5,p6,p7,p9); |
KAME | 2:479b749065ee | 9 | SDFileSystem sd(p5,p6,p7,p10),"sd"); |
KAME | 2:479b749065ee | 10 | I2C i2c(p28,p27); |
KAME | 2:479b749065ee | 11 | LocalFileSystem local("local"); |
KAME | 2:479b749065ee | 12 | Serial pc(USBTX,USBFC); |
KAME | 2:479b749065ee | 13 | |
KAME | 2:479b749065ee | 14 | |
KAME | 2:479b749065ee | 15 | SCP1000 scp1000(p5,p6,p7,p8); |
KAME | 2:479b749065ee | 16 | |
KAME | 2:479b749065ee | 17 | PwmOut pwm(p21); |
KAME | 2:479b749065ee | 18 | |
KAME | 2:479b749065ee | 19 | Ticker timer; |
KAME | 2:479b749065ee | 20 | |
KAME | 2:479b749065ee | 21 | InterruptIn flight(p11); |
KAME | 2:479b749065ee | 22 | |
KAME | 2:479b749065ee | 23 | void start1(); |
KAME | 2:479b749065ee | 24 | |
KAME | 2:479b749065ee | 25 | |
KAME | 2:479b749065ee | 26 | main() |
KAME | 2:479b749065ee | 27 | { |
KAME | 2:479b749065ee | 28 | while(true) |
KAME | 2:479b749065ee | 29 | { |
KAME | 2:479b749065ee | 30 | flight.fall(&start1); |
KAME | 2:479b749065ee | 31 | //data collect |
KAME | 2:479b749065ee | 32 | } |
KAME | 2:479b749065ee | 33 | } |
KAME | 2:479b749065ee | 34 | |
KAME | 2:479b749065ee | 35 | /*void data() |
KAME | 2:479b749065ee | 36 | { |
KAME | 2:479b749065ee | 37 | while(true){ |
KAME | 2:479b749065ee | 38 | lcd.cls(); |
KAME | 2:479b749065ee | 39 | lcd.printf("data collecting..."); |
KAME | 2:479b749065ee | 40 | } |
KAME | 2:479b749065ee | 41 | } |
KAME | 2:479b749065ee | 42 | */ |
KAME | 2:479b749065ee | 43 | /*void open() |
KAME | 2:479b749065ee | 44 | { |
KAME | 2:479b749065ee | 45 | timer.attach(&data,1.0); |
KAME | 2:479b749065ee | 46 | int start=500, end=2200; |
KAME | 2:479b749065ee | 47 | while(true){ |
KAME | 2:479b749065ee | 48 | lcd.cls(); |
KAME | 2:479b749065ee | 49 | lcd.printf("open!!"); |
KAME | 2:479b749065ee | 50 | for(int p = start; p < end; p += 20) { |
KAME | 2:479b749065ee | 51 | pwm.pulsewidth_us(p); |
KAME | 2:479b749065ee | 52 | wait_ms(20); |
KAME | 2:479b749065ee | 53 | } |
KAME | 2:479b749065ee | 54 | for(int p = end; p >=start; p -= 20) { |
KAME | 2:479b749065ee | 55 | pwm.pulsewidth_us(p); |
KAME | 2:479b749065ee | 56 | wait_ms(20); |
KAME | 2:479b749065ee | 57 | } |
KAME | 2:479b749065ee | 58 | } |
KAME | 2:479b749065ee | 59 | |
KAME | 2:479b749065ee | 60 | } |
KAME | 2:479b749065ee | 61 | */ |
KAME | 2:479b749065ee | 62 | |
KAME | 2:479b749065ee | 63 | |
KAME | 2:479b749065ee | 64 | /*void start() |
KAME | 2:479b749065ee | 65 | { |
KAME | 2:479b749065ee | 66 | wait(0.1); |
KAME | 2:479b749065ee | 67 | flight.fall(&start); |
KAME | 2:479b749065ee | 68 | flight.rise(&start); |
KAME | 2:479b749065ee | 69 | lcd.cls(); |
KAME | 2:479b749065ee | 70 | lcd.printf("2"); |
KAME | 2:479b749065ee | 71 | }*/ |
KAME | 2:479b749065ee | 72 | void start1(){ |
KAME | 2:479b749065ee | 73 | |
KAME | 2:479b749065ee | 74 | //timer.attach(&open,15); |
KAME | 2:479b749065ee | 75 | int t=0; |
KAME | 2:479b749065ee | 76 | int go=0; |
KAME | 2:479b749065ee | 77 | |
KAME | 2:479b749065ee | 78 | pwm.period_ms(20); |
KAME | 2:479b749065ee | 79 | wait_ms(100); |
KAME | 2:479b749065ee | 80 | flight.fall(&start1); |
KAME | 2:479b749065ee | 81 | flight.rise(&start1); |
KAME | 2:479b749065ee | 82 | double p0; |
KAME | 2:479b749065ee | 83 | p0=scp1000.readPressure(); |
KAME | 2:479b749065ee | 84 | //lcd.cls(); |
KAME | 2:479b749065ee | 85 | // lcd.printf("start:%f", p0); |
KAME | 2:479b749065ee | 86 | |
KAME | 2:479b749065ee | 87 | while(t<8) |
KAME | 2:479b749065ee | 88 | { |
KAME | 2:479b749065ee | 89 | t++; |
KAME | 2:479b749065ee | 90 | |
KAME | 2:479b749065ee | 91 | double p1,p2,p3; |
KAME | 2:479b749065ee | 92 | int t[3]; |
KAME | 2:479b749065ee | 93 | int i=0; |
KAME | 2:479b749065ee | 94 | while(i<3) |
KAME | 2:479b749065ee | 95 | { |
KAME | 2:479b749065ee | 96 | p1=scp1000.readPressure(); |
KAME | 2:479b749065ee | 97 | // lcd.cls(); |
KAME | 2:479b749065ee | 98 | // lcd.printf("Pressure1:%f", p1); |
KAME | 2:479b749065ee | 99 | wait(0.15); |
KAME | 2:479b749065ee | 100 | p2= scp1000.readPressure(); |
KAME | 2:479b749065ee | 101 | lcd.cls(); |
KAME | 2:479b749065ee | 102 | lcd.printf("Pressure2:%f", p2); |
KAME | 2:479b749065ee | 103 | wait(0.15); |
KAME | 2:479b749065ee | 104 | p3=scp1000.readPressure(); |
KAME | 2:479b749065ee | 105 | lcd.cls(); |
KAME | 2:479b749065ee | 106 | lcd.printf("Pressure3:%f", p3); |
KAME | 2:479b749065ee | 107 | wait(0.15); |
KAME | 2:479b749065ee | 108 | t[i]=(p1+p2+p3)/3; |
KAME | 2:479b749065ee | 109 | lcd.cls(); |
KAME | 2:479b749065ee | 110 | lcd.printf("Pressure:%f", t[i]); |
KAME | 2:479b749065ee | 111 | i++; |
KAME | 2:479b749065ee | 112 | |
KAME | 2:479b749065ee | 113 | } |
KAME | 2:479b749065ee | 114 | |
KAME | 2:479b749065ee | 115 | if(t[0]<t[1]) |
KAME | 2:479b749065ee | 116 | { |
KAME | 2:479b749065ee | 117 | if(t[1]<t[2]) |
KAME | 2:479b749065ee | 118 | { |
KAME | 2:479b749065ee | 119 | |
KAME | 2:479b749065ee | 120 | lcd.cls(); |
KAME | 2:479b749065ee | 121 | lcd.printf("open!!!"); |
KAME | 2:479b749065ee | 122 | int start=2000, end=3500; |
KAME | 2:479b749065ee | 123 | for(int a=0;a<2;a++) |
KAME | 2:479b749065ee | 124 | { |
KAME | 2:479b749065ee | 125 | for(int p = start; p < end; p += 20) { |
KAME | 2:479b749065ee | 126 | pwm.pulsewidth_us(p); |
KAME | 2:479b749065ee | 127 | wait_ms(20); |
KAME | 2:479b749065ee | 128 | |
KAME | 2:479b749065ee | 129 | } |
KAME | 2:479b749065ee | 130 | lcd.cls(); |
KAME | 2:479b749065ee | 131 | lcd.printf("A"); |
KAME | 2:479b749065ee | 132 | for(int p = end; p >=start; p -= 20) { |
KAME | 2:479b749065ee | 133 | pwm.pulsewidth_us(p); |
KAME | 2:479b749065ee | 134 | wait_ms(20); |
KAME | 2:479b749065ee | 135 | } |
KAME | 2:479b749065ee | 136 | lcd.cls(); |
KAME | 2:479b749065ee | 137 | lcd.printf("B"); |
KAME | 2:479b749065ee | 138 | } |
KAME | 2:479b749065ee | 139 | go=1; |
KAME | 2:479b749065ee | 140 | }else{ |
KAME | 2:479b749065ee | 141 | lcd.cls(); |
KAME | 2:479b749065ee | 142 | lcd.printf("rising2..%d,%d,%d",t[0],t[1],t[2]); |
KAME | 2:479b749065ee | 143 | wait(0.4); |
KAME | 2:479b749065ee | 144 | } |
KAME | 2:479b749065ee | 145 | }else{ |
KAME | 2:479b749065ee | 146 | lcd.cls(); |
KAME | 2:479b749065ee | 147 | lcd.printf("rising1..%d,%d,%d",t[0],t[1],t[2]); |
KAME | 2:479b749065ee | 148 | wait(0.4); |
KAME | 2:479b749065ee | 149 | } |
KAME | 2:479b749065ee | 150 | |
KAME | 2:479b749065ee | 151 | if(go==1) |
KAME | 2:479b749065ee | 152 | { |
KAME | 2:479b749065ee | 153 | |
KAME | 2:479b749065ee | 154 | while(true) |
KAME | 2:479b749065ee | 155 | { |
KAME | 2:479b749065ee | 156 | //data collecting |
KAME | 2:479b749065ee | 157 | } |
KAME | 2:479b749065ee | 158 | } |
KAME | 2:479b749065ee | 159 | |
KAME | 2:479b749065ee | 160 | } |
KAME | 2:479b749065ee | 161 | int start=2000, end=3500; |
KAME | 2:479b749065ee | 162 | //timer.attach(&data,5.0); |
KAME | 2:479b749065ee | 163 | for(int b=0;b<2;b++) |
KAME | 2:479b749065ee | 164 | { |
KAME | 2:479b749065ee | 165 | lcd.cls(); |
KAME | 2:479b749065ee | 166 | lcd.printf("open!!"); |
KAME | 2:479b749065ee | 167 | for(int p = start; p < end; p += 20) { |
KAME | 2:479b749065ee | 168 | pwm.pulsewidth_us(p); |
KAME | 2:479b749065ee | 169 | wait_ms(20); |
KAME | 2:479b749065ee | 170 | } |
KAME | 2:479b749065ee | 171 | lcd.cls(); |
KAME | 2:479b749065ee | 172 | lcd.printf("A"); |
KAME | 2:479b749065ee | 173 | for(int p = end; p >=start; p -= 20) { |
KAME | 2:479b749065ee | 174 | pwm.pulsewidth_us(p); |
KAME | 2:479b749065ee | 175 | wait_ms(20); |
KAME | 2:479b749065ee | 176 | } |
KAME | 2:479b749065ee | 177 | lcd.cls(); |
KAME | 2:479b749065ee | 178 | lcd.printf("B"); |
KAME | 2:479b749065ee | 179 | |
KAME | 2:479b749065ee | 180 | } |
KAME | 2:479b749065ee | 181 | lcd.cls(); |
KAME | 2:479b749065ee | 182 | while(true){ |
KAME | 2:479b749065ee | 183 | |
KAME | 2:479b749065ee | 184 | //data collect |
KAME | 2:479b749065ee | 185 | } |
KAME | 2:479b749065ee | 186 | |
KAME | 2:479b749065ee | 187 | } |
KAME | 2:479b749065ee | 188 | |
KAME | 2:479b749065ee | 189 | |
KAME | 2:479b749065ee | 190 | |
KAME | 2:479b749065ee | 191 | |
KAME | 2:479b749065ee | 192 |