lab1 part2
Dependencies: PinDetect lab1_part2 mbed
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); } }