LDR

Dependencies:   N5110 mbed

Fork of 1620_App_Board_Temperature_Sensor by Craig Evans

main.cpp

Committer:
eencae
Date:
2017-02-28
Revision:
2:1c669cb14c5b
Parent:
1:b5c4ca3bf074
Child:
3:ce5582846693

File content as of revision 2:1c669cb14c5b:

/* ELEC1620 Application Board Example

LDR

(c) Dr Craig A. Evans, University of Leeds, Feb 2017

*/

#include "mbed.h"
#include "N5110.h"

// JP1 on board must be in 2-3 position
N5110 lcd(p8,p9,p10,p11,p13,p21);

// LDR connected to ADC pin
AnalogIn ldr(p15);

int main() {
    
    lcd.init();  // need to initialise the LCD
    
    while(1) {
        
        // clear the display at the start of every new frame
        lcd.clear();
        
        // lcd is 84 pixels wide x 48 pixels high
        
        //  x, y,  width, height, outline
        lcd.drawRect(12,20,60,8,0);
        
        float value = ldr.read();  // read in the LDR value in range 0.0 to 1.0
        
        int width = int(value*60.0f); // convert to an int in the range 0.0 to 60.0
        
        // draw a bar of the correct width
        lcd.drawRect(12,20,width,8,1); // the 1 makes a black rectangle
        
        // update the LCD
        lcd.refresh(); 
        // small delay between readings
        wait(0.2);
        
    }
}