New group

Dependencies:   mbed

Fork of TAIST_modbus by Supachai Vorapojpisut

Committer:
SaiiPruttapon
Date:
Wed Mar 14 07:28:50 2018 +0000
Revision:
1:f84cb7cea5ea
Parent:
0:f306cb0263a6
Child:
2:6a3ab2abe970
botton code & time

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vsupacha 0:f306cb0263a6 1 #include "mbed.h"
vsupacha 0:f306cb0263a6 2 #include "modbus.h"
vsupacha 0:f306cb0263a6 3
vsupacha 0:f306cb0263a6 4 DigitalOut myled(LED1);
SaiiPruttapon 1:f84cb7cea5ea 5 InterruptIn button(USER_BUTTON);
vsupacha 0:f306cb0263a6 6 RawSerial pc(USBTX, USBRX);
vsupacha 0:f306cb0263a6 7
SaiiPruttapon 1:f84cb7cea5ea 8 float cunt=0.0;
SaiiPruttapon 1:f84cb7cea5ea 9
vsupacha 0:f306cb0263a6 10 void serial_callback()
vsupacha 0:f306cb0263a6 11 {
vsupacha 0:f306cb0263a6 12 uint8_t frame[6];
vsupacha 0:f306cb0263a6 13 char ch = pc.getc();
SaiiPruttapon 1:f84cb7cea5ea 14 if (modbus_parser(ch, frame)) {
vsupacha 0:f306cb0263a6 15 }
vsupacha 0:f306cb0263a6 16 }
vsupacha 0:f306cb0263a6 17
SaiiPruttapon 1:f84cb7cea5ea 18 void pressed()
SaiiPruttapon 1:f84cb7cea5ea 19 {
SaiiPruttapon 1:f84cb7cea5ea 20 cunt=cunt+0.1;
SaiiPruttapon 1:f84cb7cea5ea 21 wait(0.1);
SaiiPruttapon 1:f84cb7cea5ea 22 }
SaiiPruttapon 1:f84cb7cea5ea 23
SaiiPruttapon 1:f84cb7cea5ea 24 void released()
SaiiPruttapon 1:f84cb7cea5ea 25 {
SaiiPruttapon 1:f84cb7cea5ea 26 cunt=0;
SaiiPruttapon 1:f84cb7cea5ea 27 }
SaiiPruttapon 1:f84cb7cea5ea 28
vsupacha 0:f306cb0263a6 29 int main() {
vsupacha 0:f306cb0263a6 30 // setup code
vsupacha 0:f306cb0263a6 31 pc.attach(serial_callback);
SaiiPruttapon 1:f84cb7cea5ea 32
vsupacha 0:f306cb0263a6 33 // 1. button code
SaiiPruttapon 1:f84cb7cea5ea 34 button.fall(&pressed);
SaiiPruttapon 1:f84cb7cea5ea 35 button.rise(&released);
SaiiPruttapon 1:f84cb7cea5ea 36
vsupacha 0:f306cb0263a6 37 // 2. timer code
SaiiPruttapon 1:f84cb7cea5ea 38
vsupacha 0:f306cb0263a6 39 while(1) {
vsupacha 0:f306cb0263a6 40 // loop code
vsupacha 0:f306cb0263a6 41 myled = 1; // LED is ON
vsupacha 0:f306cb0263a6 42 wait(0.2); // 200 ms
vsupacha 0:f306cb0263a6 43 myled = 0; // LED is OFF
vsupacha 0:f306cb0263a6 44 wait(1.0); // 1 sec
vsupacha 0:f306cb0263a6 45 }
vsupacha 0:f306cb0263a6 46 }