New group

Dependencies:   mbed

Fork of TAIST_modbus by Supachai Vorapojpisut

main.cpp

Committer:
SaiiPruttapon
Date:
2018-03-14
Revision:
2:6a3ab2abe970
Parent:
1:f84cb7cea5ea
Child:
3:6c4f6182b385

File content as of revision 2:6a3ab2abe970:

#include "mbed.h"
#include "modbus.h"

DigitalOut myled(LED1);
InterruptIn button(USER_BUTTON);
RawSerial pc(USBTX, USBRX);

float cunt = 0.0;

void serial_callback()
{
    uint8_t frame[6];
    char ch = pc.getc();
    if (modbus_parser(ch, frame)) {   
    }
}

void pressed()
{
    cunt=cunt+0.1;
    wait(0.1);
}

void released()
{
    cunt=0;
}

int main() {
    // setup code
    pc.attach(serial_callback);
    
    // 1. button code
    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
    }
}