Robotic Matrim
Dependencies: PwmIn mbed C12832
Diff: main.cpp
- Revision:
- 0:04877eaa5047
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Nov 30 14:22:49 2018 +0000 @@ -0,0 +1,147 @@ +#include "mbed.h" +#include "PwmIn.h" +#include "C12832.h" + +DigitalOut myled(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +DigitalOut buzz(p18); + +DigitalOut rele1(p23); +DigitalOut rele2(p24); +DigitalOut sobe(p21); +DigitalOut desce(p22); + +C12832 lcd(p5, p7, p6, p8, p11); + +PwmIn a(p15);//CH1 +PwmIn b(p16); //CH2 +PwmIn c(p17);//CH3 +PwmIn d(p18);//CH4 + +float t, u, v, w; + +int main() { + lcd.cls(); + sobe = 1; + desce = 1; + rele1 = 1; + rele2 = 1; + buzz = 0; + while(1) { + lcd.cls(); + t = (a.dutycycle()*100); + u = (b.dutycycle()*100); + v = (c.dutycycle()*100); + w = (d.dutycycle()*100); + + // printf("a: pw = %f, period = %f\n", a.pulsewidth(), a.period()); + + if ((u<12)&(u>10)){ + lcd.locate(25,0); + lcd.printf("u 0"); + myled3 = 0; + myled4 = 0; + sobe = 1; + desce = 1; + } + if (u<10){ + lcd.locate(25,0); + lcd.printf("u-1"); + myled3 = 0; + myled4 = 1; + desce = 0; + sobe = 1; + } + if (u>12){ + lcd.locate(25,0); + lcd.printf("u+1"); + myled3 = 1; + myled4 = 0; + sobe = 0; + desce = 1; + } + + if ((v<12)&(v>10)){ + lcd.locate(0,0); + lcd.printf("v 0"); + myled = 0; + myled2 = 0; + rele1 = 1; + rele2 = 1; + } + if (v<10){ + lcd.locate(0,0); + lcd.printf("v-1"); + myled = 1; + myled2 = 1; + rele2 = 0; + rele1 = 0; + } + if (v>12){ + lcd.locate(0,0); + lcd.printf("v+1"); + myled = 1; + myled2 = 0; + rele1 = 0; + rele2 = 1; + } + + + + + + + + if ((t<12)&(t>10)){ + lcd.locate(25,10); + lcd.printf("t 0"); + } + if (t<10){ + lcd.locate(25,10); + lcd.printf("t-1"); + } + if (t>12){ + lcd.locate(25,10); + lcd.printf("t+1"); + } + + + + if (w>14){ + lcd.locate(0,10); + lcd.printf("w+1"); + buzz = 1; + } + else { + lcd.locate(0,10); + lcd.printf("w 0"); + buzz = 0; + } + + /* + + if ((w<12)&(w>10)){ + lcd.locate(0,10); + lcd.printf("w 0"); + } + if (w<10){ + lcd.locate(0,10); + lcd.printf("w-1"); + } + if (w>12){ + lcd.locate(0,10); + lcd.printf("w+1"); + } + + */ + + // lcd.locate(25,10); + // lcd.printf("%f",b.dutycycle()); + // lcd.printf("pw= %f pd= %f\n", a.pulsewidth(), a.period()); + + wait(0.1); + } +} \ No newline at end of file