Sukkpranhachai Gatesichapakorn
/
TAIST_modbus
New group
Fork of TAIST_modbus by
main.cpp
- Committer:
- SaiiPruttapon
- Date:
- 2018-03-14
- Revision:
- 8:5c3395345dc1
- Parent:
- 7:774c2b305d2d
- Child:
- 9:4ddee8c61bad
File content as of revision 8:5c3395345dc1:
#include "mbed.h" #include "modbus.h" DigitalOut myled(LED1); InterruptIn button(USER_BUTTON); RawSerial pc(USBTX, USBRX); Ticker ticker; int cunt_pressed = 0; int cunt_released = 0; int x,y; void serial_callback() { uint8_t frame[6]; char ch = pc.getc(); pc.printf("%d", modbus_parser(ch, frame)); } void pressed() { if(cunt_released != 0) { y = cunt_released; modbus_update(0, y); pc.printf("released = %f sec\n",((float)modbus_read(0)*0.1)); cunt_released = 0; } if(button==0){ cunt_pressed = cunt_pressed+1; ticker.attach(callback(&pressed),0.1); } } void released() { if(cunt_pressed != 0) { x = cunt_pressed; modbus_update(1, x); pc.printf("pressed = %f sec\n",((float)modbus_read(1)*0.1)); cunt_pressed = 0; } if(button==1){ cunt_released = cunt_released+1; ticker.attach(callback(&released),0.1); } } int main() { // setup code pc.attach(serial_callback); // 1. button code button.mode(PullNone); button.fall(&pressed); button.rise(&released); // 2. timer code Ticker ticker; while(1) { // loop code myled = 1; // LED is ON wait(0.2); // 200 ms myled = 0; // LED is OFF wait(1.0); // 1 sec } }