Seatbelt cycler

Dependencies:   mbed

Committer:
mondoman
Date:
Mon Jun 23 18:26:19 2014 +0000
Revision:
2:f565b245fca9
Parent:
1:88397297a9e9
Updated for material abrasion test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mondoman 0:c91b6d9f73a2 1 #include "mbed.h"
mondoman 1:88397297a9e9 2 #include "Serial.h"
mondoman 1:88397297a9e9 3
mondoman 1:88397297a9e9 4 Serial lcd(p9, p10); // tx, rx
mondoman 1:88397297a9e9 5 void clear(void);
mondoman 1:88397297a9e9 6 void move_cursor(int, int);
mondoman 1:88397297a9e9 7
mondoman 1:88397297a9e9 8
mondoman 0:c91b6d9f73a2 9
mondoman 1:88397297a9e9 10 DigitalOut myled1(LED1);
mondoman 1:88397297a9e9 11 DigitalOut myled2(LED2);
mondoman 1:88397297a9e9 12 DigitalOut armDown(p21);
mondoman 1:88397297a9e9 13 DigitalOut armUp(p22);
mondoman 1:88397297a9e9 14 DigitalIn onSwitch(p30);
mondoman 1:88397297a9e9 15 DigitalIn runSwitch(p29);
mondoman 1:88397297a9e9 16 DigitalIn upSwitch(p28);
mondoman 1:88397297a9e9 17 DigitalIn downSwitch(p27);
mondoman 0:c91b6d9f73a2 18
mondoman 0:c91b6d9f73a2 19
mondoman 0:c91b6d9f73a2 20 int main() {
mondoman 1:88397297a9e9 21 /* State 1: Rest
mondoman 1:88397297a9e9 22 State 2: Down
mondoman 1:88397297a9e9 23 State 3: Wait2
mondoman 1:88397297a9e9 24 State 4: Up */
mondoman 1:88397297a9e9 25 wait(1);
mondoman 1:88397297a9e9 26 clear();
mondoman 1:88397297a9e9 27 lcd.printf("Seatbelt Test");
mondoman 1:88397297a9e9 28 int state = 1;
mondoman 1:88397297a9e9 29 int count = 0;
mondoman 2:f565b245fca9 30 int maxCount = 1000;
mondoman 2:f565b245fca9 31 float wait1 = 5.0;
mondoman 2:f565b245fca9 32 float wait2 = 5.0 ;
mondoman 2:f565b245fca9 33 float cylDown = 2.0;
mondoman 2:f565b245fca9 34 float cylUp = 2.0;
mondoman 0:c91b6d9f73a2 35 while(1) {
mondoman 1:88397297a9e9 36 while((onSwitch==1)&&(count<=maxCount)) {
mondoman 1:88397297a9e9 37 move_cursor(1,0);
mondoman 1:88397297a9e9 38 lcd.printf(" ");
mondoman 1:88397297a9e9 39 move_cursor(1,0);
mondoman 1:88397297a9e9 40 lcd.printf("%d Out of:%d",count,maxCount);
mondoman 1:88397297a9e9 41
mondoman 1:88397297a9e9 42 if(runSwitch==1) {
mondoman 1:88397297a9e9 43 if(state==1) { // State 1 Wait
mondoman 1:88397297a9e9 44 armDown = 0;
mondoman 1:88397297a9e9 45 myled1 = 0;
mondoman 1:88397297a9e9 46 armUp = 0;
mondoman 1:88397297a9e9 47 myled2 = 0;
mondoman 1:88397297a9e9 48 wait(wait1);
mondoman 1:88397297a9e9 49 state = 2;
mondoman 1:88397297a9e9 50 }
mondoman 1:88397297a9e9 51 else if(state==2) { // State 2 Arm Down
mondoman 1:88397297a9e9 52 armDown = 1;
mondoman 1:88397297a9e9 53 myled1 = 1;
mondoman 1:88397297a9e9 54 armUp = 0;
mondoman 1:88397297a9e9 55 myled2 = 0;
mondoman 1:88397297a9e9 56 wait(cylDown);
mondoman 1:88397297a9e9 57 state = 3;
mondoman 1:88397297a9e9 58 }
mondoman 1:88397297a9e9 59 else if(state==3) { // State 3 Wait
mondoman 1:88397297a9e9 60 armDown = 0;
mondoman 1:88397297a9e9 61 myled1 = 0;
mondoman 1:88397297a9e9 62 armUp = 0;
mondoman 1:88397297a9e9 63 myled2 = 0;
mondoman 1:88397297a9e9 64 wait(wait2);
mondoman 1:88397297a9e9 65 state = 4;
mondoman 1:88397297a9e9 66 }
mondoman 1:88397297a9e9 67 else if(state==4) { // State 4 Arm Up
mondoman 1:88397297a9e9 68 armDown = 0;
mondoman 1:88397297a9e9 69 myled1 = 0;
mondoman 1:88397297a9e9 70 armUp = 1;
mondoman 1:88397297a9e9 71 myled2 = 1;
mondoman 1:88397297a9e9 72 wait(cylUp);
mondoman 1:88397297a9e9 73 state = 1;
mondoman 1:88397297a9e9 74 count++;
mondoman 1:88397297a9e9 75 }
mondoman 1:88397297a9e9 76
mondoman 1:88397297a9e9 77 }
mondoman 1:88397297a9e9 78 else if(runSwitch==0) {
mondoman 1:88397297a9e9 79 if(upSwitch==1) {
mondoman 1:88397297a9e9 80 armUp = 1;
mondoman 1:88397297a9e9 81 myled2 = 1;
mondoman 1:88397297a9e9 82 armDown = 0;
mondoman 1:88397297a9e9 83 myled1 = 0;
mondoman 1:88397297a9e9 84 }
mondoman 1:88397297a9e9 85 else if(downSwitch==1) {
mondoman 1:88397297a9e9 86 armUp = 0;
mondoman 1:88397297a9e9 87 myled2 = 0;
mondoman 1:88397297a9e9 88 armDown = 1;
mondoman 1:88397297a9e9 89 myled1 = 1;
mondoman 1:88397297a9e9 90 }
mondoman 1:88397297a9e9 91 else {
mondoman 1:88397297a9e9 92 armUp = 0;
mondoman 1:88397297a9e9 93 armDown = 0;
mondoman 1:88397297a9e9 94 myled1 = 0;
mondoman 1:88397297a9e9 95 myled2 = 0;
mondoman 1:88397297a9e9 96 }
mondoman 1:88397297a9e9 97 }
mondoman 1:88397297a9e9 98 }
mondoman 0:c91b6d9f73a2 99 }
mondoman 0:c91b6d9f73a2 100 }
mondoman 1:88397297a9e9 101 //------clears the dispaly--------
mondoman 1:88397297a9e9 102 void clear(void) {
mondoman 1:88397297a9e9 103 lcd.putc(0xFE);
mondoman 1:88397297a9e9 104 lcd.putc(0x01);
mondoman 1:88397297a9e9 105 }
mondoman 1:88397297a9e9 106
mondoman 1:88397297a9e9 107 //----------- line 0 or 1----------
mondoman 1:88397297a9e9 108 //----------- position 0/15--------
mondoman 1:88397297a9e9 109 // (0,0) is top left position
mondoman 1:88397297a9e9 110 // (1,15) is bottom right position
mondoman 1:88397297a9e9 111 void move_cursor(int line, int pos) {
mondoman 1:88397297a9e9 112 int cp;
mondoman 1:88397297a9e9 113 cp = pos + (line * 64) +128;
mondoman 1:88397297a9e9 114 lcd.putc(0xFE);
mondoman 1:88397297a9e9 115 lcd.putc(cp);
mondoman 1:88397297a9e9 116 }