Sippakorn Saeng-aroon
/
InventorStudio_LCP2
v1.1
main.cpp@3:054df6da48b5, 2019-05-05 (annotated)
- Committer:
- sippasaeng
- Date:
- Sun May 05 17:01:42 2019 +0000
- Revision:
- 3:054df6da48b5
- Parent:
- 2:eb82f5cb5098
- Child:
- 4:4b28e4aa1742
v1.0 of LCP serial protocol, work!; -parsing; -communicate with both Unity and Mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pokpongc | 0:ef2ee7458c37 | 1 | #include "mbed.h" |
pokpongc | 0:ef2ee7458c37 | 2 | #include "QEI.h" |
pokpongc | 0:ef2ee7458c37 | 3 | |
pokpongc | 0:ef2ee7458c37 | 4 | Serial pc(USBTX, USBRX); |
pokpongc | 0:ef2ee7458c37 | 5 | |
pokpongc | 0:ef2ee7458c37 | 6 | QEI temp_dial(D11, D12, A1, 50, QEI::X4_ENCODING); |
pokpongc | 0:ef2ee7458c37 | 7 | BusIn joy_bus{D3, D4, D5, D6}; |
pokpongc | 0:ef2ee7458c37 | 8 | BusIn button_bus{D7, D9}; |
pokpongc | 1:8e3af9643155 | 9 | DigitalIn a(D7),b(D9),c(D3),d(D4),e(D5),f(D6); //Dummy pin for pulling |
pokpongc | 0:ef2ee7458c37 | 10 | |
sippasaeng | 3:054df6da48b5 | 11 | int data[8]; |
pokpongc | 0:ef2ee7458c37 | 12 | |
pokpongc | 1:8e3af9643155 | 13 | void init_(); |
pokpongc | 1:8e3af9643155 | 14 | |
pokpongc | 0:ef2ee7458c37 | 15 | int main() { |
pokpongc | 2:eb82f5cb5098 | 16 | pc.baud(9600); |
pokpongc | 2:eb82f5cb5098 | 17 | uint16_t pulse = 0; |
pokpongc | 1:8e3af9643155 | 18 | init_(); |
pokpongc | 0:ef2ee7458c37 | 19 | while(1){ |
pokpongc | 0:ef2ee7458c37 | 20 | pulse = temp_dial.getPulses()/2; |
pokpongc | 2:eb82f5cb5098 | 21 | if (pulse >= 350) |
pokpongc | 2:eb82f5cb5098 | 22 | pulse = 350; |
pokpongc | 2:eb82f5cb5098 | 23 | else if (pulse <= 0) |
pokpongc | 2:eb82f5cb5098 | 24 | pulse = 0; |
pokpongc | 2:eb82f5cb5098 | 25 | data[0] = 0x77; |
sippasaeng | 3:054df6da48b5 | 26 | data[1] = button_bus.read(); |
sippasaeng | 3:054df6da48b5 | 27 | data[2] = joy_bus.read(); |
pokpongc | 2:eb82f5cb5098 | 28 | if (pulse > 255){ |
sippasaeng | 3:054df6da48b5 | 29 | data[3] = pulse-255; |
sippasaeng | 3:054df6da48b5 | 30 | data[4] = 255; |
pokpongc | 2:eb82f5cb5098 | 31 | }else{ |
sippasaeng | 3:054df6da48b5 | 32 | data[3] = 0; |
sippasaeng | 3:054df6da48b5 | 33 | data[4] = pulse; |
pokpongc | 2:eb82f5cb5098 | 34 | } |
pokpongc | 2:eb82f5cb5098 | 35 | data[5] = 0x00; |
pokpongc | 2:eb82f5cb5098 | 36 | data[6] = 0x00; |
pokpongc | 2:eb82f5cb5098 | 37 | data[7] = 0x0A; |
sippasaeng | 3:054df6da48b5 | 38 | |
sippasaeng | 3:054df6da48b5 | 39 | //Data overwrite for serial transmit debug |
sippasaeng | 3:054df6da48b5 | 40 | /* data[0]= 0x00; |
sippasaeng | 3:054df6da48b5 | 41 | data[1]= 0x01; |
sippasaeng | 3:054df6da48b5 | 42 | data[2]= 0x02; |
sippasaeng | 3:054df6da48b5 | 43 | data[3]= 0x03; |
sippasaeng | 3:054df6da48b5 | 44 | data[4]= 0x04; |
sippasaeng | 3:054df6da48b5 | 45 | data[5]= 0x05; |
sippasaeng | 3:054df6da48b5 | 46 | data[6]= 0x06; |
sippasaeng | 3:054df6da48b5 | 47 | data[0]= 0x00; |
sippasaeng | 3:054df6da48b5 | 48 | */ |
sippasaeng | 3:054df6da48b5 | 49 | |
pokpongc | 2:eb82f5cb5098 | 50 | for (int i = 0; i<=7; i++) |
pokpongc | 2:eb82f5cb5098 | 51 | pc.putc(data[i]); |
pokpongc | 0:ef2ee7458c37 | 52 | } |
pokpongc | 0:ef2ee7458c37 | 53 | } |
pokpongc | 0:ef2ee7458c37 | 54 | |
pokpongc | 1:8e3af9643155 | 55 | |
pokpongc | 1:8e3af9643155 | 56 | void init_(){ |
pokpongc | 1:8e3af9643155 | 57 | a.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 58 | b.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 59 | c.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 60 | d.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 61 | e.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 62 | f.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 63 | } |