![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code for operation of relay switch
main.cpp@1:e7eb16963bcb, 2015-11-02 (annotated)
- Committer:
- shekhar
- Date:
- Mon Nov 02 07:40:37 2015 +0000
- Revision:
- 1:e7eb16963bcb
- Parent:
- 0:845fb927f526
changed to 25msec
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shekhar | 1:e7eb16963bcb | 1 | //checked for pulse duration of 1ms,3ms, 25ms, 100ms, 300ms - working for all! |
shekhar | 0:845fb927f526 | 2 | |
shekhar | 0:845fb927f526 | 3 | #include "mbed.h" |
shekhar | 0:845fb927f526 | 4 | void writereg(uint8_t ,uint8_t ); |
shekhar | 0:845fb927f526 | 5 | uint8_t readreg(uint8_t); |
shekhar | 0:845fb927f526 | 6 | Serial pc(USBTX, USBRX); |
shekhar | 0:845fb927f526 | 7 | DigitalOut BCN(D10); //slave select or chip select |
shekhar | 0:845fb927f526 | 8 | DigitalOut TX(D9); //slave select or chip select |
shekhar | 0:845fb927f526 | 9 | |
shekhar | 0:845fb927f526 | 10 | main() |
shekhar | 0:845fb927f526 | 11 | { |
shekhar | 0:845fb927f526 | 12 | char ch; |
shekhar | 0:845fb927f526 | 13 | while(1){ |
shekhar | 0:845fb927f526 | 14 | printf("press any char\n"); |
shekhar | 0:845fb927f526 | 15 | ch = pc.getc(); |
shekhar | 0:845fb927f526 | 16 | if(ch == 'A') |
shekhar | 0:845fb927f526 | 17 | { |
shekhar | 0:845fb927f526 | 18 | putchar(ch); |
shekhar | 0:845fb927f526 | 19 | BCN = 1; |
shekhar | 1:e7eb16963bcb | 20 | wait_ms(25);//min 1 ms//25ms (3-4 times of contact bounce + operate pulse) |
shekhar | 0:845fb927f526 | 21 | BCN = 0; |
shekhar | 0:845fb927f526 | 22 | } |
shekhar | 0:845fb927f526 | 23 | if(ch == 'B') |
shekhar | 0:845fb927f526 | 24 | { |
shekhar | 0:845fb927f526 | 25 | putchar(ch); |
shekhar | 0:845fb927f526 | 26 | TX = 1; |
shekhar | 1:e7eb16963bcb | 27 | wait_ms(25);//min 1 ms//25ms (3-4 times of contact bounce + operate pulse) |
shekhar | 0:845fb927f526 | 28 | TX = 0; |
shekhar | 0:845fb927f526 | 29 | }} |
shekhar | 0:845fb927f526 | 30 | } |