Nextion - HMI - 1. zadatak
Dependencies: mbed
main.cpp
- Committer:
- dfraj
- Date:
- 2022-01-24
- Revision:
- 3:83cf2072b25d
- Parent:
- 2:d4209a7955c3
- Child:
- 4:11d61285b2f0
File content as of revision 3:83cf2072b25d:
#include "mbed.h"
Serial nextion(p28, p27);
PwmOut servo(p21);
char buffer[20];
int znak = 0;
uint8_t pozicija = 0;
void Rx_interrupt(void){
char c;
if(nextion.readable()) {
c = nextion.getc();
buffer[znak] = c;
znak++;
if ((znak >= 2) && (buffer[znak-1] == 0x0d)) {
pozicija = 0;
for(int i = 0; i < 3; i++) {
if(buffer[i] == 0x0d) break;
pozicija = pozicija * 10 + (buffer[i] - 48);
}
servo.pulsewidth_us(5.56*pozicija+1000);
memset(buffer,0,strlen(buffer));
znak = 0;
}
}
}
int main(){
nextion .attach(&Rx_interrupt, Serial::RxIrq);
servo.period(0.02);
while (1) {
wait(1.0);
}
}