Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@2:38d752717527, 2021-10-27 (annotated)
- Committer:
- mgimple
- Date:
- Wed Oct 27 17:48:12 2021 +0000
- Revision:
- 2:38d752717527
- Parent:
- 1:d706fb07041f
- Child:
- 3:0170897aa173
temperature reading too high ; photo cell not responsive;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mgimple | 0:61f876d07ef5 | 1 | #include "mbed.h" |
mgimple | 0:61f876d07ef5 | 2 | |
mgimple | 0:61f876d07ef5 | 3 | Serial pc(USBTX,USBRX); |
mgimple | 0:61f876d07ef5 | 4 | DigitalOut Led1(LED1); |
mgimple | 0:61f876d07ef5 | 5 | DigitalOut Led2(LED2); |
mgimple | 0:61f876d07ef5 | 6 | DigitalOut Led3(LED3); |
mgimple | 0:61f876d07ef5 | 7 | DigitalOut Led4(LED4); |
mgimple | 0:61f876d07ef5 | 8 | AnalogIn therm(p19); |
mgimple | 0:61f876d07ef5 | 9 | AnalogIn light(p20); |
mgimple | 0:61f876d07ef5 | 10 | |
mgimple | 0:61f876d07ef5 | 11 | |
mgimple | 0:61f876d07ef5 | 12 | float volt_raw; //raw data read from thermistor |
mgimple | 0:61f876d07ef5 | 13 | float volt; //final voltage after conversion |
mgimple | 0:61f876d07ef5 | 14 | float temp; //converted temperature in degrees celsius |
mgimple | 0:61f876d07ef5 | 15 | float light_volt; //light voltage multiplied by 3.3 from mbed |
mgimple | 0:61f876d07ef5 | 16 | float light_res; //resistance through photocell |
mgimple | 0:61f876d07ef5 | 17 | float light_volt_raw; //raw voltage through photocell |
mgimple | 0:61f876d07ef5 | 18 | void temp_read(); //temperature reading function |
mgimple | 0:61f876d07ef5 | 19 | void light_read(); //light reading function |
mgimple | 2:38d752717527 | 20 | |
mgimple | 0:61f876d07ef5 | 21 | |
mgimple | 0:61f876d07ef5 | 22 | int main() |
mgimple | 0:61f876d07ef5 | 23 | { |
mgimple | 1:d706fb07041f | 24 | while(1) { |
mgimple | 2:38d752717527 | 25 | temp_read(); |
mgimple | 2:38d752717527 | 26 | |
mgimple | 2:38d752717527 | 27 | light_read(); |
mgimple | 2:38d752717527 | 28 | } |
mgimple | 2:38d752717527 | 29 | } |
mgimple | 0:61f876d07ef5 | 30 | |
mgimple | 2:38d752717527 | 31 | void temp_read() //main temperature reading command to be called upon |
mgimple | 2:38d752717527 | 32 | { |
mgimple | 2:38d752717527 | 33 | volt_raw = therm.read(); //sets the raw data as a variable |
mgimple | 2:38d752717527 | 34 | volt = volt_raw; //converts raw voltage to the correct scale for our mbed *3.3 |
mgimple | 2:38d752717527 | 35 | temp = -1481.96+sqrt(((2.1962e6)+((1.8639-volt)/(3.88e-6)))); //converts voltage to temperature |
mgimple | 2:38d752717527 | 36 | pc.printf("TEMP %f Volts %3.1f Celsius \r\n",volt, temp); |
mgimple | 2:38d752717527 | 37 | wait(1); |
mgimple | 2:38d752717527 | 38 | |
mgimple | 2:38d752717527 | 39 | if (temp>=15) { |
mgimple | 2:38d752717527 | 40 | Led1=1; |
mgimple | 2:38d752717527 | 41 | if (temp>=20) { |
mgimple | 2:38d752717527 | 42 | Led2=1; |
mgimple | 2:38d752717527 | 43 | if (temp>=25) { |
mgimple | 2:38d752717527 | 44 | Led3=1; |
mgimple | 0:61f876d07ef5 | 45 | } |
mgimple | 0:61f876d07ef5 | 46 | } |
mgimple | 2:38d752717527 | 47 | } |
mgimple | 2:38d752717527 | 48 | } |
mgimple | 0:61f876d07ef5 | 49 | |
mgimple | 1:d706fb07041f | 50 | |
mgimple | 2:38d752717527 | 51 | void light_read() //main light reading command to be called upon |
mgimple | 2:38d752717527 | 52 | { |
mgimple | 2:38d752717527 | 53 | light_volt_raw=light.read(); //sets the raw data as a variable |
mgimple | 2:38d752717527 | 54 | light_res=(10000/light_volt_raw)-10000; //converting voltage to resistance |
mgimple | 2:38d752717527 | 55 | light_volt=light_volt_raw*3.3; //mbed outputs 3.3 volts |
mgimple | 2:38d752717527 | 56 | pc.printf("LIGHT %1.3f Voltz 6.2%f Ohms\r\n",light_volt,light_res); |
mgimple | 2:38d752717527 | 57 | wait(1); |
mgimple | 2:38d752717527 | 58 | if (light_volt<0.3) { //the sensor is "completely blocked" by a finger at most values under 0.3 volts. The whole photocell has to be covered however because even if a bit is showing it will read higher than 0.3 |
mgimple | 2:38d752717527 | 59 | Led4=1; |
mgimple | 0:61f876d07ef5 | 60 | } |
mgimple | 2:38d752717527 | 61 | if (light_volt>0.3) { |
mgimple | 2:38d752717527 | 62 | Led4=0; |
mgimple | 2:38d752717527 | 63 | } |
mgimple | 2:38d752717527 | 64 | } |