quiz1_1

Dependencies:   mbed

Committer:
shih775007
Date:
Wed Mar 01 10:09:07 2017 +0000
Revision:
0:ef4ce59f2913
quiz1_1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shih775007 0:ef4ce59f2913 1 #include "mbed.h"
shih775007 0:ef4ce59f2913 2
shih775007 0:ef4ce59f2913 3 #define BREATHE_PERIOD 4500 // ms
shih775007 0:ef4ce59f2913 4 #define INHALE_PERIOD (BREATHE_PERIOD / 4)
shih775007 0:ef4ce59f2913 5 #define EXHALE_PERIOD (BREATHE_PERIOD / 2)
shih775007 0:ef4ce59f2913 6 #define HOLD_PERIOD (BREATHE_PERIOD / 8)
shih775007 0:ef4ce59f2913 7
shih775007 0:ef4ce59f2913 8
shih775007 0:ef4ce59f2913 9 //BusOut leds(LED1, LED2, LED3, LED4);
shih775007 0:ef4ce59f2913 10 PwmOut led(D6);
shih775007 0:ef4ce59f2913 11
shih775007 0:ef4ce59f2913 12 int main() {
shih775007 0:ef4ce59f2913 13 float brightness;
shih775007 0:ef4ce59f2913 14
shih775007 0:ef4ce59f2913 15 while(1) {
shih775007 0:ef4ce59f2913 16 for (int i = 0; i <= 32; i++) {
shih775007 0:ef4ce59f2913 17 brightness = i * i / (float)(32 * 32);
shih775007 0:ef4ce59f2913 18 led = brightness;
shih775007 0:ef4ce59f2913 19 wait_ms(INHALE_PERIOD / 32);
shih775007 0:ef4ce59f2913 20 }
shih775007 0:ef4ce59f2913 21
shih775007 0:ef4ce59f2913 22 wait_ms(HOLD_PERIOD);
shih775007 0:ef4ce59f2913 23
shih775007 0:ef4ce59f2913 24 for (int i = 0; i <= 32; i++) {
shih775007 0:ef4ce59f2913 25 brightness = 1- (i * i / (float)(32 * 32));
shih775007 0:ef4ce59f2913 26 led = brightness;
shih775007 0:ef4ce59f2913 27 wait_ms(EXHALE_PERIOD / 32);
shih775007 0:ef4ce59f2913 28 }
shih775007 0:ef4ce59f2913 29
shih775007 0:ef4ce59f2913 30 wait_ms(HOLD_PERIOD);
shih775007 0:ef4ce59f2913 31 }
shih775007 0:ef4ce59f2913 32 }