Sippakorn Saeng-aroon
/
InventorStudio_LCP2
v1.1
main.cpp@2:eb82f5cb5098, 2019-05-05 (annotated)
- Committer:
- pokpongc
- Date:
- Sun May 05 16:06:29 2019 +0000
- Revision:
- 2:eb82f5cb5098
- Parent:
- 1:8e3af9643155
- Child:
- 3:054df6da48b5
Add protocal
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 | |
pokpongc | 2:eb82f5cb5098 | 11 | char 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; |
pokpongc | 2:eb82f5cb5098 | 26 | data[1] = (char)button_bus.read(); |
pokpongc | 2:eb82f5cb5098 | 27 | data[2] = (char)joy_bus.read(); |
pokpongc | 2:eb82f5cb5098 | 28 | if (pulse > 255){ |
pokpongc | 2:eb82f5cb5098 | 29 | data[3] = (char)pulse-255; |
pokpongc | 2:eb82f5cb5098 | 30 | data[4] = (char)255; |
pokpongc | 2:eb82f5cb5098 | 31 | }else{ |
pokpongc | 2:eb82f5cb5098 | 32 | data[3] = (char)0; |
pokpongc | 2:eb82f5cb5098 | 33 | data[4] = (char)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; |
pokpongc | 2:eb82f5cb5098 | 38 | for (int i = 0; i<=7; i++) |
pokpongc | 2:eb82f5cb5098 | 39 | pc.putc(data[i]); |
pokpongc | 0:ef2ee7458c37 | 40 | } |
pokpongc | 0:ef2ee7458c37 | 41 | } |
pokpongc | 0:ef2ee7458c37 | 42 | |
pokpongc | 1:8e3af9643155 | 43 | |
pokpongc | 1:8e3af9643155 | 44 | void init_(){ |
pokpongc | 1:8e3af9643155 | 45 | a.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 46 | b.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 47 | c.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 48 | d.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 49 | e.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 50 | f.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 51 | } |