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
- Committer:
- logostarr
- Date:
- 2022-09-02
- Revision:
- 0:ea651607da73
- Child:
- 8:db9bcb92ff2a
File content as of revision 0:ea651607da73:
#include "mbed.h"
#include "PinDetect.h"
DigitalOut red(p5);
PwmOut led(LED1);
DigitalIn pblight(p8);
PinDetect pbdim(p7);
PinDetect pbbright(p6);
float volatile brightness = 0.5f;
void pbdim_hit_callback (void) {
if(1.0f > brightness ||brightness >= 0.0f) {
brightness+= 0.1f;
}
}
void pbbright_hit_callback (void) {
if (0.0f < brightness || brightness <= 1.0f) {
brightness -= 0.1f;
}
}
int main() {
pblight.mode(PullUp);
pbdim.mode(PullUp);
pbbright.mode(PullUp);
wait(0.001);
pbdim.attach_deasserted(&pbdim_hit_callback);
pbdim.setSampleFrequency();
pbbright.attach_deasserted(&pbbright_hit_callback);
pbbright.setSampleFrequency();
while(1) {
red = !pblight;
led = brightness;
wait(.5);
}
}