Sippakorn Saeng-aroon
/
InventorStudio_LCP2
v1.1
Diff: main.cpp
- Revision:
- 2:eb82f5cb5098
- Parent:
- 1:8e3af9643155
- Child:
- 3:054df6da48b5
--- a/main.cpp Sun May 05 10:19:43 2019 +0000 +++ b/main.cpp Sun May 05 16:06:29 2019 +0000 @@ -8,18 +8,35 @@ 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(115200); - long pulse = 0; + pc.baud(9600); + uint16_t pulse = 0; init_(); while(1){ pulse = temp_dial.getPulses()/2; - pc.printf("%d \t%d\n",joy_bus.read(), button_bus.read()); - - + 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]); } }