Sippakorn Saeng-aroon
/
InventorStudio_LCP2
v1.1
main.cpp
- Committer:
- sippasaeng
- Date:
- 2019-05-05
- Revision:
- 3:054df6da48b5
- Parent:
- 2:eb82f5cb5098
- Child:
- 4:4b28e4aa1742
File content as of revision 3:054df6da48b5:
#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 int 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] = button_bus.read(); data[2] = joy_bus.read(); if (pulse > 255){ data[3] = pulse-255; data[4] = 255; }else{ data[3] = 0; data[4] = pulse; } data[5] = 0x00; data[6] = 0x00; data[7] = 0x0A; //Data overwrite for serial transmit debug /* data[0]= 0x00; data[1]= 0x01; data[2]= 0x02; data[3]= 0x03; data[4]= 0x04; data[5]= 0x05; data[6]= 0x06; data[0]= 0x00; */ 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); }