Matej Slapsak
/
UV_LED
test
Diff: main.cpp
- Revision:
- 0:43c630791109
- Child:
- 1:ceefb922cff9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Dec 10 14:22:31 2018 +0000 @@ -0,0 +1,163 @@ +#include "mbed.h" + +//indikacija rgb +#define OFF 0 +#define ON 1 + +DigitalOut myled_blue(p16); +DigitalOut myled_green(p30); +DigitalOut myled_red(p15); + +DigitalIn start1(p11); +DigitalIn start2(p12); +DigitalIn start3(p13); +DigitalIn start4(p10); + +//timerji +Timer timerProgram; + +//nastavitev pwm signalov +PwmOut pwm1 (p21); // +PwmOut pwm2(p22); + +//dodano za merjenje toka in napetosti +//def analogno merjenje nap in toka +AnalogIn measVol (p17); +AnalogIn measCurrG (p18); +AnalogIn measCurrH(p19); +float voltageMeas = 0.0; +float voltageCalc = 0.0; +float currentMeasG = 0.0; +float currentCalcG = 0.0; +float currentMeasH = 0.0; +float currentCalcH = 0.0; + +//funkcija za nastavljanje baudrate pri serijski komunikaciji na PC +void baud(int baudrate) +{ + Serial s(USBTX, USBRX); + s.baud(baudrate); +} + +void merjenjeTokaInNapetosti() { + + printf ("\r\n"); + printf ("<------- \r\n"); + printf ("Measurement: \r\n"); + DigitalOut pwmGD (p21); + DigitalOut pwmHD (p22); + pwmGD = 1; + pwmHD = 1; + + wait(0.1); + + voltageMeas = measVol.read(); + voltageMeas *= 3.3; + voltageCalc = voltageMeas * 9.15; //8.2 + + currentMeasG = measCurrG.read(); + currentMeasG *= 3.3; + currentCalcG = currentMeasG * 1.259; + + currentMeasH = measCurrH.read(); + currentMeasH *= 3.3; + currentCalcH = currentMeasH * 1.279; + wait(0.1); + + printf("Voltage: %f V\r\n", voltageCalc); + printf("Current1: %f A\r\n", currentCalcG); + printf("Current2: %f A\r\n", currentCalcH); + printf ("-------> \r\n"); + + pwmGD = 0; + pwmHD = 0; + + } + + + +int main() +{ + //hitrost serijske komunikacije + baud(115200); + + while(1) + { + myled_blue = OFF; + myled_green = OFF; + myled_red = OFF; + + if(start2 == 0) + { + myled_green = ON; + printf ("\r\n"); + printf ("<------- \r\n"); + + //merjenjeTokaInNapetosti(); + + //nastavitev pwm period + pwm1.period_ms(100); + pwm2.period_ms(100); + + pwm1=0; + pwm2=0; + + printf ("Start \r\n"); + printf("pwm1 read: %f\n\r",pwm1.read()); + printf("pwm2 read: %f\n\r",pwm2.read()); + + //printf ("\r\n"); + + //printf("pwm1 read: %f\n\r",pwm1.read()*100); + + //izvajanje krmilja + printf ("PWM set \r\n"); + + pwm1.pulsewidth_ms(20); + + printf("pwm1 read: %f\n\r",pwm1.read()); + printf("pwm2 read: %f\n\r",pwm2.read()); + wait(0.1); + + printf ("PWM set \r\n"); + pwm1.pulsewidth_ms(60); + + printf("pwm1 read: %f\n\r",pwm1.read()); + printf("pwm2 read: %f\n\r",pwm2.read()); + wait(0.2); + printf ("PWM off \r\n"); + pwm1 = 0; + pwm2 = 0; + + + printf("pwm1 read: %f\n\r",pwm1.read()); + printf("pwm2 read: %f\n\r",pwm2.read()); + printf ("End \r\n"); + printf ("-------> \r\n"); + wait(2); + myled_green = OFF; + } + + else if(start1 == 0) + { + myled_blue = ON; + merjenjeTokaInNapetosti(); + wait(2); + } + + else if(start3 == 0) + { + myled_red = ON; + wait(2); + } + + else if(start4 == 0) + { + myled_blue = ON; + myled_red = ON; + myled_green = ON; + wait(2); + } + + } +}