lab1 part2
Dependencies: PinDetect lab1_part2 mbed
main.cpp@10:00a557218002, 2022-09-08 (annotated)
- Committer:
- mus3
- Date:
- Thu Sep 08 07:32:51 2022 +0000
- Revision:
- 10:00a557218002
- Parent:
- 9:e5c16d5c49d7
lab1 part2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
logostarr | 0:ea651607da73 | 1 | #include "mbed.h" |
logostarr | 0:ea651607da73 | 2 | #include "PinDetect.h" |
logostarr | 0:ea651607da73 | 3 | |
logostarr | 0:ea651607da73 | 4 | PwmOut led(LED1); |
logostarr | 0:ea651607da73 | 5 | PinDetect pbdim(p7); |
logostarr | 0:ea651607da73 | 6 | PinDetect pbbright(p6); |
logostarr | 0:ea651607da73 | 7 | float volatile brightness = 0.5f; |
logostarr | 0:ea651607da73 | 8 | void pbdim_hit_callback (void) { |
mus3 | 8:db9bcb92ff2a | 9 | if(1.0f > brightness || brightness >= 0.0f) { |
logostarr | 0:ea651607da73 | 10 | brightness+= 0.1f; |
logostarr | 0:ea651607da73 | 11 | } |
logostarr | 0:ea651607da73 | 12 | } |
logostarr | 0:ea651607da73 | 13 | void pbbright_hit_callback (void) { |
logostarr | 0:ea651607da73 | 14 | if (0.0f < brightness || brightness <= 1.0f) { |
logostarr | 0:ea651607da73 | 15 | brightness -= 0.1f; |
logostarr | 0:ea651607da73 | 16 | } |
logostarr | 0:ea651607da73 | 17 | } |
logostarr | 0:ea651607da73 | 18 | int main() { |
logostarr | 0:ea651607da73 | 19 | pbdim.mode(PullUp); |
logostarr | 0:ea651607da73 | 20 | pbbright.mode(PullUp); |
logostarr | 0:ea651607da73 | 21 | wait(0.001); |
logostarr | 0:ea651607da73 | 22 | |
logostarr | 0:ea651607da73 | 23 | pbdim.attach_deasserted(&pbdim_hit_callback); |
logostarr | 0:ea651607da73 | 24 | pbdim.setSampleFrequency(); |
logostarr | 0:ea651607da73 | 25 | pbbright.attach_deasserted(&pbbright_hit_callback); |
logostarr | 0:ea651607da73 | 26 | pbbright.setSampleFrequency(); |
logostarr | 0:ea651607da73 | 27 | while(1) { |
logostarr | 0:ea651607da73 | 28 | led = brightness; |
mus3 | 9:e5c16d5c49d7 | 29 | wait(.2); |
logostarr | 0:ea651607da73 | 30 | } |
logostarr | 0:ea651607da73 | 31 | } |
logostarr | 0:ea651607da73 | 32 |