AUP_Lab5_MMA7660

Dependencies:   C12832 MMA7660 mbed

Fork of AUP_Lab4_LCD by Lei Lei

main.cpp

Committer:
BrentLei
Date:
2015-07-07
Revision:
1:08431d9e3d95
Parent:
0:65e58765adf7
Child:
2:09ee85ab1717

File content as of revision 1:08431d9e3d95:

#include "mbed.h"
#include "C12832.h"

PwmOut led(D5);
DigitalIn button_up(A2);
DigitalIn button_center(D4);
DigitalIn button_down(A3);
C12832 lcd(D11, D13, D12, D7, D10);

double brightness = 1.0;
double brightness_inc = 0.1;

int main()
{
    int bt_flag = 0;
    lcd.cls();
    lcd.locate(0,0);
    lcd.printf("Hello PWM!\r\n");
    // Set PWM
    led.write(brightness);

    while (1) {
        bt_flag = 1;
        if(button_up==1)
            brightness -= brightness_inc;
        else if(button_down==1)
            brightness += brightness_inc;
        else if(button_center==1)
            brightness = (brightness>0.5)?1.0:0.0;
        else
            bt_flag = 0;
        if(bt_flag==1)
        {
            brightness = (brightness>1.0)?0.0:brightness;
            brightness = (brightness<0.0)?1.0:brightness;
            led.write(brightness);
            lcd.locate(0,0);
            lcd.printf("Brightness = %.1f\r\n", 1.0-brightness);
        }
        wait(0.2); // 200 ms
    }
}