han back
/
CLEO_SMART_LIGHT
SMART CLEO Smart Light
main.cpp@0:7403bd322eb6, 2017-12-06 (annotated)
- Committer:
- SMART_CLEO
- Date:
- Wed Dec 06 08:52:08 2017 +0000
- Revision:
- 0:7403bd322eb6
SMART_CLEO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SMART_CLEO | 0:7403bd322eb6 | 1 | #include "mbed.h" |
SMART_CLEO | 0:7403bd322eb6 | 2 | #include "TextLCD.h" |
SMART_CLEO | 0:7403bd322eb6 | 3 | |
SMART_CLEO | 0:7403bd322eb6 | 4 | PinName pin_CDS = PB_0; |
SMART_CLEO | 0:7403bd322eb6 | 5 | PinName pin_LEDR = PB_6; |
SMART_CLEO | 0:7403bd322eb6 | 6 | PinName pin_LEDG = PB_5; |
SMART_CLEO | 0:7403bd322eb6 | 7 | PinName pin_LEDB = PB_4; |
SMART_CLEO | 0:7403bd322eb6 | 8 | |
SMART_CLEO | 0:7403bd322eb6 | 9 | AnalogIn adc_CDS(pin_CDS); |
SMART_CLEO | 0:7403bd322eb6 | 10 | |
SMART_CLEO | 0:7403bd322eb6 | 11 | // rs, rw, e, d0-d3 |
SMART_CLEO | 0:7403bd322eb6 | 12 | TextLCD lcd(PB_12, PB_13, PB_14, PB_15, PA_9, PA_10, PA_11); |
SMART_CLEO | 0:7403bd322eb6 | 13 | |
SMART_CLEO | 0:7403bd322eb6 | 14 | PwmOut LEDR(pin_LEDR); |
SMART_CLEO | 0:7403bd322eb6 | 15 | PwmOut LEDG(pin_LEDG); |
SMART_CLEO | 0:7403bd322eb6 | 16 | PwmOut LEDB(pin_LEDB); |
SMART_CLEO | 0:7403bd322eb6 | 17 | |
SMART_CLEO | 0:7403bd322eb6 | 18 | float LED_Ctrl(int value); |
SMART_CLEO | 0:7403bd322eb6 | 19 | |
SMART_CLEO | 0:7403bd322eb6 | 20 | int main() { |
SMART_CLEO | 0:7403bd322eb6 | 21 | |
SMART_CLEO | 0:7403bd322eb6 | 22 | int ADC_Data; |
SMART_CLEO | 0:7403bd322eb6 | 23 | float Brightness; |
SMART_CLEO | 0:7403bd322eb6 | 24 | LEDR = LED_Ctrl(0); |
SMART_CLEO | 0:7403bd322eb6 | 25 | LEDG = LED_Ctrl(0); |
SMART_CLEO | 0:7403bd322eb6 | 26 | LEDB = LED_Ctrl(0); |
SMART_CLEO | 0:7403bd322eb6 | 27 | |
SMART_CLEO | 0:7403bd322eb6 | 28 | lcd.printf(" ADC Data : \n"); |
SMART_CLEO | 0:7403bd322eb6 | 29 | lcd.printf(""); |
SMART_CLEO | 0:7403bd322eb6 | 30 | while(1) { |
SMART_CLEO | 0:7403bd322eb6 | 31 | ADC_Data = adc_CDS.read()*4095; |
SMART_CLEO | 0:7403bd322eb6 | 32 | lcd.locate(12, 0); |
SMART_CLEO | 0:7403bd322eb6 | 33 | lcd.printf("%4d", ADC_Data); |
SMART_CLEO | 0:7403bd322eb6 | 34 | if(ADC_Data > 3000) |
SMART_CLEO | 0:7403bd322eb6 | 35 | ADC_Data = 3000; |
SMART_CLEO | 0:7403bd322eb6 | 36 | ADC_Data /= 30; |
SMART_CLEO | 0:7403bd322eb6 | 37 | Brightness = (100.0 - ADC_Data) / 100; |
SMART_CLEO | 0:7403bd322eb6 | 38 | LEDR = Brightness; |
SMART_CLEO | 0:7403bd322eb6 | 39 | LEDG = Brightness; |
SMART_CLEO | 0:7403bd322eb6 | 40 | LEDB = Brightness; |
SMART_CLEO | 0:7403bd322eb6 | 41 | wait(0.5); |
SMART_CLEO | 0:7403bd322eb6 | 42 | } |
SMART_CLEO | 0:7403bd322eb6 | 43 | } |
SMART_CLEO | 0:7403bd322eb6 | 44 | |
SMART_CLEO | 0:7403bd322eb6 | 45 | // brightness Control 0 ~ 100(%) |
SMART_CLEO | 0:7403bd322eb6 | 46 | float LED_Ctrl(int value) |
SMART_CLEO | 0:7403bd322eb6 | 47 | { |
SMART_CLEO | 0:7403bd322eb6 | 48 | float brightness = value; |
SMART_CLEO | 0:7403bd322eb6 | 49 | brightness /= 100; |
SMART_CLEO | 0:7403bd322eb6 | 50 | return brightness; |
SMART_CLEO | 0:7403bd322eb6 | 51 | } |