LDR

Dependencies:   N5110 mbed

Fork of 1620_App_Board_Temperature_Sensor by Craig Evans

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* ELEC1620 Application Board Example
00002 
00003 LDR
00004 
00005 (c) Dr Craig A. Evans, University of Leeds, Feb 2017
00006 
00007 */
00008 
00009 #include "mbed.h"
00010 #include "N5110.h"
00011 
00012 // JP1 on board must be in 2-3 position
00013 N5110 lcd(p8,p9,p10,p11,p13,p21);
00014 
00015 // LDR connected to ADC pin
00016 AnalogIn ldr(p15);
00017 
00018 int main() {
00019     
00020     lcd.init();  // need to initialise the LCD
00021     
00022     while(1) {
00023         
00024         // clear the display at the start of every new frame
00025         lcd.clear();
00026         
00027         // lcd is 84 pixels wide x 48 pixels high
00028         
00029         //  x, y,  width, height, fill type
00030         lcd.drawRect(12,20,60,8,FILL_TRANSPARENT);
00031         
00032         float value = ldr.read();  // read in the LDR value in range 0.0 to 1.0
00033         
00034         int width = int(value*60.0f); // convert to an int in the range 0.0 to 60.0
00035         
00036         // draw a bar of the correct width
00037         lcd.drawRect(12,20,width,8,FILL_BLACK); 
00038         
00039         // update the LCD
00040         lcd.refresh(); 
00041         // small delay between readings
00042         wait(0.2);
00043         
00044     }
00045 }
00046 
00047