1

Dependencies:   UiSM_Lab_5_pomiary mbed

Fork of L5_odczyt by abm mechatronika

Committer:
Pawel_13
Date:
Fri Apr 17 14:48:48 2015 +0000
Revision:
0:e7d867077aec
UiSM Lab 5 17.04.2015

Who changed what in which revision?

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