Sukkpranhachai Gatesichapakorn
/
TAIST_modbus
New group
Fork of TAIST_modbus by
main.cpp
- Committer:
- nengzix
- Date:
- 2018-03-14
- Revision:
- 7:774c2b305d2d
- Parent:
- 6:5bb5238f2f6e
- Child:
- 8:5c3395345dc1
File content as of revision 7:774c2b305d2d:
#include "mbed.h" #include "modbus.h" DigitalOut myled(LED1); InterruptIn button(USER_BUTTON); RawSerial pc(USBTX, USBRX); 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 = %d\n",modbus_read(0)); cunt_released = 0; } while(button==0){ cunt_pressed = cunt_pressed+1; wait(0.1); } } void released() { if(cunt_pressed != 0) { x = cunt_pressed; modbus_update(1, x); pc.printf("pressed = %d\n",modbus_read(1)); cunt_pressed = 0; } while(button==1){ cunt_released = cunt_released+1; wait(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 while(1) { // loop code myled = 1; // LED is ON wait(0.2); // 200 ms myled = 0; // LED is OFF wait(1.0); // 1 sec } }