Sippakorn Saeng-aroon
/
InventorStudio_LCP2
v1.1
main.cpp
- Committer:
- pokpongc
- Date:
- 2019-05-05
- Revision:
- 2:eb82f5cb5098
- Parent:
- 1:8e3af9643155
- Child:
- 3:054df6da48b5
File content as of revision 2:eb82f5cb5098:
#include "mbed.h" #include "QEI.h" Serial pc(USBTX, USBRX); QEI temp_dial(D11, D12, A1, 50, QEI::X4_ENCODING); BusIn joy_bus{D3, D4, D5, D6}; BusIn button_bus{D7, D9}; DigitalIn a(D7),b(D9),c(D3),d(D4),e(D5),f(D6); //Dummy pin for pulling char data[8]; void init_(); int main() { pc.baud(9600); uint16_t pulse = 0; init_(); while(1){ pulse = temp_dial.getPulses()/2; if (pulse >= 350) pulse = 350; else if (pulse <= 0) pulse = 0; data[0] = 0x77; data[1] = (char)button_bus.read(); data[2] = (char)joy_bus.read(); if (pulse > 255){ data[3] = (char)pulse-255; data[4] = (char)255; }else{ data[3] = (char)0; data[4] = (char)pulse; } data[5] = 0x00; data[6] = 0x00; data[7] = 0x0A; for (int i = 0; i<=7; i++) pc.putc(data[i]); } } void init_(){ a.mode(PullDown); b.mode(PullDown); c.mode(PullDown); d.mode(PullDown); e.mode(PullDown); f.mode(PullDown); }