1

Dependencies:   mbed

Committer:
abm_mechatronika
Date:
Mon Apr 20 07:50:00 2015 +0000
Revision:
0:22d018a3b548
fotorez

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abm_mechatronika 0:22d018a3b548 1 #include "mbed.h"
abm_mechatronika 0:22d018a3b548 2
abm_mechatronika 0:22d018a3b548 3 int analog_zero_0 = 0;
abm_mechatronika 0:22d018a3b548 4 AnalogIn fotorezystor(PTB0);
abm_mechatronika 0:22d018a3b548 5 Serial pc(USBTX, USBRX);
abm_mechatronika 0:22d018a3b548 6
abm_mechatronika 0:22d018a3b548 7 float voltage(AnalogIn czujnik, float zero_analog) {
abm_mechatronika 0:22d018a3b548 8 return (czujnik.read() - zero_analog) * 2.9035;
abm_mechatronika 0:22d018a3b548 9 }
abm_mechatronika 0:22d018a3b548 10
abm_mechatronika 0:22d018a3b548 11 int main() {
abm_mechatronika 0:22d018a3b548 12 pc.baud(9600);
abm_mechatronika 0:22d018a3b548 13 int i=0;
abm_mechatronika 0:22d018a3b548 14 int p=0;
abm_mechatronika 0:22d018a3b548 15 int r=0;
abm_mechatronika 0:22d018a3b548 16 int k=0;
abm_mechatronika 0:22d018a3b548 17 float o=0;
abm_mechatronika 0:22d018a3b548 18 float m,n;
abm_mechatronika 0:22d018a3b548 19 float suma=0;
abm_mechatronika 0:22d018a3b548 20 float suma2=0;
abm_mechatronika 0:22d018a3b548 21
abm_mechatronika 0:22d018a3b548 22 while(true) {
abm_mechatronika 0:22d018a3b548 23 m = voltage(fotorezystor, analog_zero_0);
abm_mechatronika 0:22d018a3b548 24 if (m < 0.05)
abm_mechatronika 0:22d018a3b548 25 p=1;
abm_mechatronika 0:22d018a3b548 26
abm_mechatronika 0:22d018a3b548 27 for (i=0; i<10; i++)
abm_mechatronika 0:22d018a3b548 28 {
abm_mechatronika 0:22d018a3b548 29 wait_us(10);
abm_mechatronika 0:22d018a3b548 30 m = voltage(fotorezystor, analog_zero_0);
abm_mechatronika 0:22d018a3b548 31 suma = suma + m;
abm_mechatronika 0:22d018a3b548 32 }
abm_mechatronika 0:22d018a3b548 33
abm_mechatronika 0:22d018a3b548 34 n = voltage(fotorezystor, analog_zero_0);
abm_mechatronika 0:22d018a3b548 35 if (n > 0.4)
abm_mechatronika 0:22d018a3b548 36 r = 1;
abm_mechatronika 0:22d018a3b548 37 else r=0;
abm_mechatronika 0:22d018a3b548 38
abm_mechatronika 0:22d018a3b548 39 for (i=0; i<10; i++)
abm_mechatronika 0:22d018a3b548 40 {
abm_mechatronika 0:22d018a3b548 41 wait_us(10);
abm_mechatronika 0:22d018a3b548 42 n = voltage(fotorezystor, analog_zero_0);
abm_mechatronika 0:22d018a3b548 43 suma2 = suma2 + n;
abm_mechatronika 0:22d018a3b548 44 }
abm_mechatronika 0:22d018a3b548 45
abm_mechatronika 0:22d018a3b548 46 if ((p==1) && (r==1) && (suma>suma2))
abm_mechatronika 0:22d018a3b548 47 {
abm_mechatronika 0:22d018a3b548 48 pc.printf("obrot\t%.2f\n",o);
abm_mechatronika 0:22d018a3b548 49 p=0;
abm_mechatronika 0:22d018a3b548 50 o=o+0.25;
abm_mechatronika 0:22d018a3b548 51 }
abm_mechatronika 0:22d018a3b548 52
abm_mechatronika 0:22d018a3b548 53 pc.printf("%.d\n",k);
abm_mechatronika 0:22d018a3b548 54 k++;
abm_mechatronika 0:22d018a3b548 55 wait_ms(10);
abm_mechatronika 0:22d018a3b548 56 suma = m;
abm_mechatronika 0:22d018a3b548 57 suma2 = n;
abm_mechatronika 0:22d018a3b548 58 }
abm_mechatronika 0:22d018a3b548 59 }