URS - LV11 - HMI - 3. zadatak - Servo
Dependencies: mbed
Revision 0:0bb9abf8a951, committed 2022-01-19
- Comitter:
- dfraj
- Date:
- Wed Jan 19 14:42:24 2022 +0000
- Child:
- 1:a59853df510d
- Commit message:
- URS - LV11 - 3. zadatak - Servo
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Jan 19 14:42:24 2022 +0000
@@ -0,0 +1,39 @@
+#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 >= 3) && (buffer[znak-1] == 0xff) && (buffer[znak-2] == 0xff) && (buffer[znak-3] == 0xff)) {
+ buffer[znak-3] = '\0';
+ pozicija = 0;
+ for(int i = 0; i < 3; i++) {
+ if(buffer[i] == '\0') 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);
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jan 19 14:42:24 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file