AUP_Lab3_Interrupt

Dependencies:   mbed

Fork of Lab3_Interrupt by 璇 李

Committer:
BrentLei
Date:
Sat Oct 31 02:43:54 2015 +0000
Revision:
1:6acc584b5a38
Parent:
0:37b9817db00a
Child:
2:ebbc2bafeb5f
nRF51

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gyth 0:37b9817db00a 1 #include "mbed.h"
gyth 0:37b9817db00a 2
gyth 0:37b9817db00a 3 PwmOut led(D5);
gyth 0:37b9817db00a 4 InterruptIn button_up(A2);
gyth 0:37b9817db00a 5 InterruptIn button_down(A3);
gyth 0:37b9817db00a 6
gyth 0:37b9817db00a 7 double brightness = 1.0;
gyth 0:37b9817db00a 8 double brightness_inc = 0.1;
gyth 0:37b9817db00a 9
gyth 0:37b9817db00a 10 void press_up()
gyth 0:37b9817db00a 11 {
gyth 0:37b9817db00a 12 brightness -= brightness_inc;
gyth 0:37b9817db00a 13 }
gyth 0:37b9817db00a 14
gyth 0:37b9817db00a 15 void press_down()
gyth 0:37b9817db00a 16 {
gyth 0:37b9817db00a 17 brightness += brightness_inc;
gyth 0:37b9817db00a 18 }
gyth 0:37b9817db00a 19
gyth 0:37b9817db00a 20 int main()
gyth 0:37b9817db00a 21 {
gyth 0:37b9817db00a 22 // Set PWM
gyth 0:37b9817db00a 23 led.write(brightness);
gyth 0:37b9817db00a 24
gyth 0:37b9817db00a 25 button_up.fall(&press_up);
gyth 0:37b9817db00a 26 button_down.fall(&press_down);
gyth 0:37b9817db00a 27
gyth 0:37b9817db00a 28 while (1) {
gyth 0:37b9817db00a 29 brightness = (brightness>1.0)?0.0:brightness;
gyth 0:37b9817db00a 30 brightness = (brightness<0.0)?1.0:brightness;
gyth 0:37b9817db00a 31 led.write(brightness);
gyth 0:37b9817db00a 32 }
gyth 0:37b9817db00a 33 }