joe carter
/
nitrocarproject
main_programs/main5.h@0:960b355eaa84, 2010-08-20 (annotated)
- Committer:
- joe
- Date:
- Fri Aug 20 11:18:40 2010 +0000
- Revision:
- 0:960b355eaa84
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joe | 0:960b355eaa84 | 1 | #include "mbed.h" |
joe | 0:960b355eaa84 | 2 | #include "LIS302.h" |
joe | 0:960b355eaa84 | 3 | #include "Servo.h" |
joe | 0:960b355eaa84 | 4 | Servo myservo(p21); |
joe | 0:960b355eaa84 | 5 | LIS302 acc (p5,p6,p7,p8); |
joe | 0:960b355eaa84 | 6 | DigitalOut led1(LED1); |
joe | 0:960b355eaa84 | 7 | DigitalOut led2(LED2); |
joe | 0:960b355eaa84 | 8 | DigitalOut led3(LED3); |
joe | 0:960b355eaa84 | 9 | DigitalOut led4(LED4); |
joe | 0:960b355eaa84 | 10 | |
joe | 0:960b355eaa84 | 11 | int main() { |
joe | 0:960b355eaa84 | 12 | float samples [5] = {0}; |
joe | 0:960b355eaa84 | 13 | int index = 0; |
joe | 0:960b355eaa84 | 14 | int flipped_right = 1; |
joe | 0:960b355eaa84 | 15 | int flipped_left = 1; |
joe | 0:960b355eaa84 | 16 | while (1) { |
joe | 0:960b355eaa84 | 17 | |
joe | 0:960b355eaa84 | 18 | wait (0.1); |
joe | 0:960b355eaa84 | 19 | samples[index] = acc.y(); |
joe | 0:960b355eaa84 | 20 | index++; |
joe | 0:960b355eaa84 | 21 | if (index >= 5) { |
joe | 0:960b355eaa84 | 22 | index = 0; |
joe | 0:960b355eaa84 | 23 | } |
joe | 0:960b355eaa84 | 24 | int i; |
joe | 0:960b355eaa84 | 25 | flipped_right = 1; |
joe | 0:960b355eaa84 | 26 | flipped_left =1; |
joe | 0:960b355eaa84 | 27 | for (i=0; i<5; i++) { |
joe | 0:960b355eaa84 | 28 | if (samples[i] > -1.0) { |
joe | 0:960b355eaa84 | 29 | flipped_left = 0; |
joe | 0:960b355eaa84 | 30 | } |
joe | 0:960b355eaa84 | 31 | |
joe | 0:960b355eaa84 | 32 | if (samples[i] < 1.0) { |
joe | 0:960b355eaa84 | 33 | flipped_right = 0; |
joe | 0:960b355eaa84 | 34 | } |
joe | 0:960b355eaa84 | 35 | } |
joe | 0:960b355eaa84 | 36 | |
joe | 0:960b355eaa84 | 37 | if (flipped_left||flipped_right) { |
joe | 0:960b355eaa84 | 38 | led1 = !led1; |
joe | 0:960b355eaa84 | 39 | led2 = !led2; |
joe | 0:960b355eaa84 | 40 | led3 = !led3; |
joe | 0:960b355eaa84 | 41 | led4 = !led4; |
joe | 0:960b355eaa84 | 42 | myservo = 1; |
joe | 0:960b355eaa84 | 43 | { |
joe | 0:960b355eaa84 | 44 | |
joe | 0:960b355eaa84 | 45 | } |
joe | 0:960b355eaa84 | 46 | } |
joe | 0:960b355eaa84 | 47 | } |
joe | 0:960b355eaa84 | 48 | } |