AUP_Lab3_Interrupt

Dependencies:   mbed

Fork of Lab3_Interrupt by 璇 李

Committer:
BrentLei
Date:
Sat Oct 31 06:34:32 2015 +0000
Revision:
2:ebbc2bafeb5f
Parent:
1:6acc584b5a38
Nordic Fixed

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);
BrentLei 2:ebbc2bafeb5f 24 led.period_ms(1);
gyth 0:37b9817db00a 25
gyth 0:37b9817db00a 26 button_up.fall(&press_up);
gyth 0:37b9817db00a 27 button_down.fall(&press_down);
gyth 0:37b9817db00a 28
gyth 0:37b9817db00a 29 while (1) {
gyth 0:37b9817db00a 30 brightness = (brightness>1.0)?0.0:brightness;
gyth 0:37b9817db00a 31 brightness = (brightness<0.0)?1.0:brightness;
gyth 0:37b9817db00a 32 led.write(brightness);
gyth 0:37b9817db00a 33 }
gyth 0:37b9817db00a 34 }