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.
project7.cpp
- Committer:
- emeastham
- Date:
- 2019-11-29
- Revision:
- 1:81a67a8d4850
- Parent:
- 0:c29828af57a5
File content as of revision 1:81a67a8d4850:
#include "mbed.h"
AnalogIn LDR(A0);
PwmOut LED(A6);
DigitalOut led2(D12);
InterruptIn button(A2);
volatile bool state=1;
void flip() {
state=!state;}
int main(){
float meas_r;
float meas_v;
LED.period_ms(10);
printf("\nAnalogIn example\n");
button.rise(&flip);
while(1){
meas_r=LDR.read();
meas_v=((meas_r-0.007f)/0.96f);
printf("measure = %f = %.0f mV\n", meas_r, meas_v);
led2.write(state);
if (state==1){
if (meas_v>0.05f){
LED.write(meas_v);}
else{ LED.write(0);
}
}
else{
LED.write(0);
}
}
}