lab1 part2

Dependencies:   PinDetect lab1_part2 mbed

Committer:
logostarr
Date:
Fri Sep 02 20:15:47 2022 +0000
Revision:
0:ea651607da73
Child:
8:db9bcb92ff2a
hi

Who changed what in which revision?

UserRevisionLine numberNew 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 DigitalOut red(p5);
logostarr 0:ea651607da73 5 PwmOut led(LED1);
logostarr 0:ea651607da73 6 DigitalIn pblight(p8);
logostarr 0:ea651607da73 7 PinDetect pbdim(p7);
logostarr 0:ea651607da73 8 PinDetect pbbright(p6);
logostarr 0:ea651607da73 9 float volatile brightness = 0.5f;
logostarr 0:ea651607da73 10 void pbdim_hit_callback (void) {
logostarr 0:ea651607da73 11 if(1.0f > brightness ||brightness >= 0.0f) {
logostarr 0:ea651607da73 12 brightness+= 0.1f;
logostarr 0:ea651607da73 13 }
logostarr 0:ea651607da73 14 }
logostarr 0:ea651607da73 15 void pbbright_hit_callback (void) {
logostarr 0:ea651607da73 16 if (0.0f < brightness || brightness <= 1.0f) {
logostarr 0:ea651607da73 17 brightness -= 0.1f;
logostarr 0:ea651607da73 18 }
logostarr 0:ea651607da73 19 }
logostarr 0:ea651607da73 20 int main() {
logostarr 0:ea651607da73 21 pblight.mode(PullUp);
logostarr 0:ea651607da73 22 pbdim.mode(PullUp);
logostarr 0:ea651607da73 23 pbbright.mode(PullUp);
logostarr 0:ea651607da73 24 wait(0.001);
logostarr 0:ea651607da73 25
logostarr 0:ea651607da73 26 pbdim.attach_deasserted(&pbdim_hit_callback);
logostarr 0:ea651607da73 27 pbdim.setSampleFrequency();
logostarr 0:ea651607da73 28 pbbright.attach_deasserted(&pbbright_hit_callback);
logostarr 0:ea651607da73 29 pbbright.setSampleFrequency();
logostarr 0:ea651607da73 30 while(1) {
logostarr 0:ea651607da73 31 red = !pblight;
logostarr 0:ea651607da73 32 led = brightness;
logostarr 0:ea651607da73 33 wait(.5);
logostarr 0:ea651607da73 34 }
logostarr 0:ea651607da73 35 }
logostarr 0:ea651607da73 36