Matej Slapsak
/
UV_LED
test
main.cpp@0:43c630791109, 2018-12-10 (annotated)
- Committer:
- laik777
- Date:
- Mon Dec 10 14:22:31 2018 +0000
- Revision:
- 0:43c630791109
- Child:
- 1:ceefb922cff9
it works;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
laik777 | 0:43c630791109 | 1 | #include "mbed.h" |
laik777 | 0:43c630791109 | 2 | |
laik777 | 0:43c630791109 | 3 | //indikacija rgb |
laik777 | 0:43c630791109 | 4 | #define OFF 0 |
laik777 | 0:43c630791109 | 5 | #define ON 1 |
laik777 | 0:43c630791109 | 6 | |
laik777 | 0:43c630791109 | 7 | DigitalOut myled_blue(p16); |
laik777 | 0:43c630791109 | 8 | DigitalOut myled_green(p30); |
laik777 | 0:43c630791109 | 9 | DigitalOut myled_red(p15); |
laik777 | 0:43c630791109 | 10 | |
laik777 | 0:43c630791109 | 11 | DigitalIn start1(p11); |
laik777 | 0:43c630791109 | 12 | DigitalIn start2(p12); |
laik777 | 0:43c630791109 | 13 | DigitalIn start3(p13); |
laik777 | 0:43c630791109 | 14 | DigitalIn start4(p10); |
laik777 | 0:43c630791109 | 15 | |
laik777 | 0:43c630791109 | 16 | //timerji |
laik777 | 0:43c630791109 | 17 | Timer timerProgram; |
laik777 | 0:43c630791109 | 18 | |
laik777 | 0:43c630791109 | 19 | //nastavitev pwm signalov |
laik777 | 0:43c630791109 | 20 | PwmOut pwm1 (p21); // |
laik777 | 0:43c630791109 | 21 | PwmOut pwm2(p22); |
laik777 | 0:43c630791109 | 22 | |
laik777 | 0:43c630791109 | 23 | //dodano za merjenje toka in napetosti |
laik777 | 0:43c630791109 | 24 | //def analogno merjenje nap in toka |
laik777 | 0:43c630791109 | 25 | AnalogIn measVol (p17); |
laik777 | 0:43c630791109 | 26 | AnalogIn measCurrG (p18); |
laik777 | 0:43c630791109 | 27 | AnalogIn measCurrH(p19); |
laik777 | 0:43c630791109 | 28 | float voltageMeas = 0.0; |
laik777 | 0:43c630791109 | 29 | float voltageCalc = 0.0; |
laik777 | 0:43c630791109 | 30 | float currentMeasG = 0.0; |
laik777 | 0:43c630791109 | 31 | float currentCalcG = 0.0; |
laik777 | 0:43c630791109 | 32 | float currentMeasH = 0.0; |
laik777 | 0:43c630791109 | 33 | float currentCalcH = 0.0; |
laik777 | 0:43c630791109 | 34 | |
laik777 | 0:43c630791109 | 35 | //funkcija za nastavljanje baudrate pri serijski komunikaciji na PC |
laik777 | 0:43c630791109 | 36 | void baud(int baudrate) |
laik777 | 0:43c630791109 | 37 | { |
laik777 | 0:43c630791109 | 38 | Serial s(USBTX, USBRX); |
laik777 | 0:43c630791109 | 39 | s.baud(baudrate); |
laik777 | 0:43c630791109 | 40 | } |
laik777 | 0:43c630791109 | 41 | |
laik777 | 0:43c630791109 | 42 | void merjenjeTokaInNapetosti() { |
laik777 | 0:43c630791109 | 43 | |
laik777 | 0:43c630791109 | 44 | printf ("\r\n"); |
laik777 | 0:43c630791109 | 45 | printf ("<------- \r\n"); |
laik777 | 0:43c630791109 | 46 | printf ("Measurement: \r\n"); |
laik777 | 0:43c630791109 | 47 | DigitalOut pwmGD (p21); |
laik777 | 0:43c630791109 | 48 | DigitalOut pwmHD (p22); |
laik777 | 0:43c630791109 | 49 | pwmGD = 1; |
laik777 | 0:43c630791109 | 50 | pwmHD = 1; |
laik777 | 0:43c630791109 | 51 | |
laik777 | 0:43c630791109 | 52 | wait(0.1); |
laik777 | 0:43c630791109 | 53 | |
laik777 | 0:43c630791109 | 54 | voltageMeas = measVol.read(); |
laik777 | 0:43c630791109 | 55 | voltageMeas *= 3.3; |
laik777 | 0:43c630791109 | 56 | voltageCalc = voltageMeas * 9.15; //8.2 |
laik777 | 0:43c630791109 | 57 | |
laik777 | 0:43c630791109 | 58 | currentMeasG = measCurrG.read(); |
laik777 | 0:43c630791109 | 59 | currentMeasG *= 3.3; |
laik777 | 0:43c630791109 | 60 | currentCalcG = currentMeasG * 1.259; |
laik777 | 0:43c630791109 | 61 | |
laik777 | 0:43c630791109 | 62 | currentMeasH = measCurrH.read(); |
laik777 | 0:43c630791109 | 63 | currentMeasH *= 3.3; |
laik777 | 0:43c630791109 | 64 | currentCalcH = currentMeasH * 1.279; |
laik777 | 0:43c630791109 | 65 | wait(0.1); |
laik777 | 0:43c630791109 | 66 | |
laik777 | 0:43c630791109 | 67 | printf("Voltage: %f V\r\n", voltageCalc); |
laik777 | 0:43c630791109 | 68 | printf("Current1: %f A\r\n", currentCalcG); |
laik777 | 0:43c630791109 | 69 | printf("Current2: %f A\r\n", currentCalcH); |
laik777 | 0:43c630791109 | 70 | printf ("-------> \r\n"); |
laik777 | 0:43c630791109 | 71 | |
laik777 | 0:43c630791109 | 72 | pwmGD = 0; |
laik777 | 0:43c630791109 | 73 | pwmHD = 0; |
laik777 | 0:43c630791109 | 74 | |
laik777 | 0:43c630791109 | 75 | } |
laik777 | 0:43c630791109 | 76 | |
laik777 | 0:43c630791109 | 77 | |
laik777 | 0:43c630791109 | 78 | |
laik777 | 0:43c630791109 | 79 | int main() |
laik777 | 0:43c630791109 | 80 | { |
laik777 | 0:43c630791109 | 81 | //hitrost serijske komunikacije |
laik777 | 0:43c630791109 | 82 | baud(115200); |
laik777 | 0:43c630791109 | 83 | |
laik777 | 0:43c630791109 | 84 | while(1) |
laik777 | 0:43c630791109 | 85 | { |
laik777 | 0:43c630791109 | 86 | myled_blue = OFF; |
laik777 | 0:43c630791109 | 87 | myled_green = OFF; |
laik777 | 0:43c630791109 | 88 | myled_red = OFF; |
laik777 | 0:43c630791109 | 89 | |
laik777 | 0:43c630791109 | 90 | if(start2 == 0) |
laik777 | 0:43c630791109 | 91 | { |
laik777 | 0:43c630791109 | 92 | myled_green = ON; |
laik777 | 0:43c630791109 | 93 | printf ("\r\n"); |
laik777 | 0:43c630791109 | 94 | printf ("<------- \r\n"); |
laik777 | 0:43c630791109 | 95 | |
laik777 | 0:43c630791109 | 96 | //merjenjeTokaInNapetosti(); |
laik777 | 0:43c630791109 | 97 | |
laik777 | 0:43c630791109 | 98 | //nastavitev pwm period |
laik777 | 0:43c630791109 | 99 | pwm1.period_ms(100); |
laik777 | 0:43c630791109 | 100 | pwm2.period_ms(100); |
laik777 | 0:43c630791109 | 101 | |
laik777 | 0:43c630791109 | 102 | pwm1=0; |
laik777 | 0:43c630791109 | 103 | pwm2=0; |
laik777 | 0:43c630791109 | 104 | |
laik777 | 0:43c630791109 | 105 | printf ("Start \r\n"); |
laik777 | 0:43c630791109 | 106 | printf("pwm1 read: %f\n\r",pwm1.read()); |
laik777 | 0:43c630791109 | 107 | printf("pwm2 read: %f\n\r",pwm2.read()); |
laik777 | 0:43c630791109 | 108 | |
laik777 | 0:43c630791109 | 109 | //printf ("\r\n"); |
laik777 | 0:43c630791109 | 110 | |
laik777 | 0:43c630791109 | 111 | //printf("pwm1 read: %f\n\r",pwm1.read()*100); |
laik777 | 0:43c630791109 | 112 | |
laik777 | 0:43c630791109 | 113 | //izvajanje krmilja |
laik777 | 0:43c630791109 | 114 | printf ("PWM set \r\n"); |
laik777 | 0:43c630791109 | 115 | |
laik777 | 0:43c630791109 | 116 | pwm1.pulsewidth_ms(20); |
laik777 | 0:43c630791109 | 117 | |
laik777 | 0:43c630791109 | 118 | printf("pwm1 read: %f\n\r",pwm1.read()); |
laik777 | 0:43c630791109 | 119 | printf("pwm2 read: %f\n\r",pwm2.read()); |
laik777 | 0:43c630791109 | 120 | wait(0.1); |
laik777 | 0:43c630791109 | 121 | |
laik777 | 0:43c630791109 | 122 | printf ("PWM set \r\n"); |
laik777 | 0:43c630791109 | 123 | pwm1.pulsewidth_ms(60); |
laik777 | 0:43c630791109 | 124 | |
laik777 | 0:43c630791109 | 125 | printf("pwm1 read: %f\n\r",pwm1.read()); |
laik777 | 0:43c630791109 | 126 | printf("pwm2 read: %f\n\r",pwm2.read()); |
laik777 | 0:43c630791109 | 127 | wait(0.2); |
laik777 | 0:43c630791109 | 128 | printf ("PWM off \r\n"); |
laik777 | 0:43c630791109 | 129 | pwm1 = 0; |
laik777 | 0:43c630791109 | 130 | pwm2 = 0; |
laik777 | 0:43c630791109 | 131 | |
laik777 | 0:43c630791109 | 132 | |
laik777 | 0:43c630791109 | 133 | printf("pwm1 read: %f\n\r",pwm1.read()); |
laik777 | 0:43c630791109 | 134 | printf("pwm2 read: %f\n\r",pwm2.read()); |
laik777 | 0:43c630791109 | 135 | printf ("End \r\n"); |
laik777 | 0:43c630791109 | 136 | printf ("-------> \r\n"); |
laik777 | 0:43c630791109 | 137 | wait(2); |
laik777 | 0:43c630791109 | 138 | myled_green = OFF; |
laik777 | 0:43c630791109 | 139 | } |
laik777 | 0:43c630791109 | 140 | |
laik777 | 0:43c630791109 | 141 | else if(start1 == 0) |
laik777 | 0:43c630791109 | 142 | { |
laik777 | 0:43c630791109 | 143 | myled_blue = ON; |
laik777 | 0:43c630791109 | 144 | merjenjeTokaInNapetosti(); |
laik777 | 0:43c630791109 | 145 | wait(2); |
laik777 | 0:43c630791109 | 146 | } |
laik777 | 0:43c630791109 | 147 | |
laik777 | 0:43c630791109 | 148 | else if(start3 == 0) |
laik777 | 0:43c630791109 | 149 | { |
laik777 | 0:43c630791109 | 150 | myled_red = ON; |
laik777 | 0:43c630791109 | 151 | wait(2); |
laik777 | 0:43c630791109 | 152 | } |
laik777 | 0:43c630791109 | 153 | |
laik777 | 0:43c630791109 | 154 | else if(start4 == 0) |
laik777 | 0:43c630791109 | 155 | { |
laik777 | 0:43c630791109 | 156 | myled_blue = ON; |
laik777 | 0:43c630791109 | 157 | myled_red = ON; |
laik777 | 0:43c630791109 | 158 | myled_green = ON; |
laik777 | 0:43c630791109 | 159 | wait(2); |
laik777 | 0:43c630791109 | 160 | } |
laik777 | 0:43c630791109 | 161 | |
laik777 | 0:43c630791109 | 162 | } |
laik777 | 0:43c630791109 | 163 | } |