New group

Dependencies:   mbed

Fork of TAIST_modbus by Supachai Vorapojpisut

main.cpp

Committer:
SaiiPruttapon
Date:
2018-03-14
Revision:
5:843e67c675c1
Parent:
4:f6bce90e2872
Child:
6:5bb5238f2f6e

File content as of revision 5:843e67c675c1:

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

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

float cunt_pressed = 0.0;
float cunt_released = 0.0;
float x,y;

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

void pressed()
{
    while(button=='0'){
        cunt_pressed =  cunt_pressed+1;
        if(cunt_released != 0)
        {
            y = cunt_released;
            printf("released = %f\n",y);
            cunt_released = 0;
        }
        wait(0.1);
    }
}

void released()
{
    while(button=='1'){
        cunt_released = cunt_released+1;
        if(cunt_pressed != 0)
        {
            x = cunt_pressed;
            printf("pressed = %f\n",x);
            cunt_pressed = 0;
        }
        wait(0.1);
        }
}

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
    }
}